Skip to content

Commit

Permalink
Updated UserDefaultsStore
Browse files Browse the repository at this point in the history
  • Loading branch information
yakovmanshin committed May 13, 2024
1 parent c83fda1 commit 860e6b8
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ final public class UserDefaultsStore {
extension UserDefaultsStore: SynchronousMutableFeatureFlagStore {

public func valueSync<Value>(for key: FeatureFlagKey) -> Result<Value, FeatureFlagStoreError> {
guard !(Value.self is ExpressibleByNilLiteral.Type) else {
return .failure(.otherError(Error.optionalValuesAreNotSupported))
}

guard let anyValue = userDefaults.object(forKey: key) else { return .failure(.valueNotFound) }
guard let value = anyValue as? Value else { return .failure(.typeMismatch) }
return .success(value)
}

public func setValueSync<Value>(_ value: Value, for key: FeatureFlagKey) throws {
guard !(value is ExpressibleByNilLiteral) else {
throw FeatureFlagStoreError.otherError(Error.optionalValuesAreNotSupported)
}

userDefaults.set(value, forKey: key)
}

Expand Down

0 comments on commit 860e6b8

Please sign in to comment.