You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,20 @@ if defaults.has(key) {
41
41
```
42
42
> If you just need to know that a key/value pair exists, **without actually using the value**, use the `has()` method instead of the optional `get(for:key)`. For complex objects it will prevent any unnecessary deserialization.
43
43
44
+
### Implicit Member Expression
45
+
46
+
You can find a convenience wrapper for your keys by extending `DefaultsKey`. This allows you use [Implicit Member Expression](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/implicit-member-expression):
47
+
```swift
48
+
// Extend with a custom key
49
+
extensionDefaultsKey {
50
+
staticlet someKey =Key<String>("someKey")
51
+
}
52
+
53
+
// Then use it like this
54
+
defaults.set("Some key", for: .someKey)
55
+
defaults.get(for: .someKey) // Output: Some key
56
+
```
57
+
44
58
### Complex objects
45
59
46
60
To store a complex object just conform to the [Codable](https://developer.apple.com/documentation/swift/codable) protocol:
0 commit comments