From c69422e0f8e6499d8db4d2cf3ba2f82c918ad9df Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Mon, 18 Nov 2024 11:57:17 -0500 Subject: [PATCH] [iOS] Fallback to default value correctly for optional preferences For preferences with optional types, the container check was incorrectly casting to the full `ValueType` which itself was already optional instead of the optionally-erased `V` type which would cause a successful cast to an `Optional.some(nil)` rather than to a proper `nil` value --- ios/brave-ios/Sources/Preferences/Preferences.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/brave-ios/Sources/Preferences/Preferences.swift b/ios/brave-ios/Sources/Preferences/Preferences.swift index 24f19066331d..d336f18f2cd2 100644 --- a/ios/brave-ios/Sources/Preferences/Preferences.swift +++ b/ios/brave-ios/Sources/Preferences/Preferences.swift @@ -131,7 +131,7 @@ extension Preferences.Option where ValueType: ExpressibleByNilLiteral { defaultValue: ValueType, container: UserDefaults ) where V: UserDefaultsEncodable, ValueType == V? { - let initialValue = (container.value(forKey: key) as? ValueType) ?? defaultValue + let initialValue = (container.value(forKey: key) as? V) ?? defaultValue self.init( key: key, initialValue: initialValue,