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: Sources/Defaults/Defaults.swift
+29
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,35 @@ open class DefaultsKey<ValueType>: DefaultsKeys {
34
34
35
35
publicextensionUserDefaults{
36
36
37
+
/// Get the defaults Enum (type String) value for the given `DefaultsKey`. The preferred way to do this is to pass the static key variable defined in the `DefaultsKeys` extension.
38
+
///
39
+
/// ```
40
+
/// static let enumType = DefaultsKey<SomeEnumStringType?>("the enumType's defaults key")
41
+
/// ```
42
+
public subscript<T:RawRepresentable>(key:DefaultsKey<T?>)->T?where T.RawValue ==String{
/// Get the defaults Enum (type Int) value for the given `DefaultsKey`. The preferred way to do this is to pass the static key variable defined in the `DefaultsKeys` extension.
53
+
///
54
+
/// ```
55
+
/// static let enumType = DefaultsKey<SomeEnumIntType?>("the enumType's defaults key")
56
+
/// ```
57
+
public subscript<T:RawRepresentable>(key:DefaultsKey<T?>)->T?where T.RawValue ==Int{
58
+
get{
59
+
returnT(rawValue:integer(forKey: key.key))
60
+
}
61
+
set{
62
+
set(newValue?.rawValue, forKey: key.key)
63
+
}
64
+
}
65
+
37
66
/// Get the defaults String value for the given `DefaultsKey`. The preferred way to do this is to pass the static key variable defined in the `DefaultsKeys` extension.
0 commit comments