@@ -121,6 +121,30 @@ public struct Defaults {
121121 }
122122 }
123123
124+ // MARK: - RawRepresentable
125+
126+ /// Returns the value associated with the specified key.
127+ ///
128+ /// - Parameter key: The key.
129+ /// - Returns: A `ValueType` or nil if the key was not found.
130+ public func get< ValueType: RawRepresentable > ( for key: Key < ValueType > ) -> ValueType ? where ValueType. RawValue: Codable {
131+ let convertedKey = Key < ValueType . RawValue > ( key. _key)
132+ if let raw = get ( for: convertedKey) {
133+ return ValueType ( rawValue: raw)
134+ }
135+ return nil
136+ }
137+
138+ /// Sets a value associated with the specified key.
139+ ///
140+ /// - Parameters:
141+ /// - some: The value to set.
142+ /// - key: The associated `Key<ValueType>`.
143+ public func set< ValueType: RawRepresentable > ( _ value: ValueType , for key: Key < ValueType > ) where ValueType. RawValue: Codable {
144+ let convertedKey = Key < ValueType . RawValue > ( key. _key)
145+ set ( value. rawValue, for: convertedKey)
146+ }
147+
124148 /// Removes given bundle's persistent domain
125149 ///
126150 /// - Parameter type: Bundle.
@@ -156,29 +180,3 @@ public struct Defaults {
156180 }
157181 }
158182}
159-
160- // MARK: ValueType with RawRepresentable conformance
161-
162- extension Defaults {
163- /// Returns the value associated with the specified key.
164- ///
165- /// - Parameter key: The key.
166- /// - Returns: A `ValueType` or nil if the key was not found.
167- public func get< ValueType: RawRepresentable > ( for key: Key < ValueType > ) -> ValueType ? where ValueType. RawValue: Codable {
168- let convertedKey = Key < ValueType . RawValue > ( key. _key)
169- if let raw = get ( for: convertedKey) {
170- return ValueType ( rawValue: raw)
171- }
172- return nil
173- }
174-
175- /// Sets a value associated with the specified key.
176- ///
177- /// - Parameters:
178- /// - some: The value to set.
179- /// - key: The associated `Key<ValueType>`.
180- public func set< ValueType: RawRepresentable > ( _ value: ValueType , for key: Key < ValueType > ) where ValueType. RawValue: Codable {
181- let convertedKey = Key < ValueType . RawValue > ( key. _key)
182- set ( value. rawValue, for: convertedKey)
183- }
184- }
0 commit comments