> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# An easy way to maintain UserDefaults key
- URL: https://developerinsider.co/an-easy-way-to-maintain-userdefaults-key/
- Published: 2020-05-31T05:04:14.000Z
- Updated: 2020-12-05T11:07:04.000Z
- Author: Vineet Choudhary
- Tags: Tips, Xcode, iOS, UserDefault, Swift

You can use `#function` literal to get the property name as UserDefault key. In the following example, `#function` will get replaced by `accessToken`. Be aware, changing the property names may break functionality for the existing users.

```swift
extension UserDefaults {
    var accessToken: String? {
        get {
            return string(forKey: #function)
        }
        set {
            set(newValue, forKey: #function)
            synchronize()
        }
    }
}

```