-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storing nil in String? results in "" #162
Comments
can confirm this happening, this is quite a dangerous bug Below the branch always evaluates as true Defaults[.authToken] = nil
if let authToken = Defaults[.authToken] {
} |
I can see this issue too |
It's not a bug, you didn't define the extension DefaultsKeys {
static let authToken = DefaultsKey<String?>("authToken", defaultValue: nil)
} |
@farzadshbfn no, it is a bug, trust me.
this returns "" |
Well that's weird, because I "just" checked it before posting it 🤔 |
what version u used for testing @farzadshbfn . We use 4.0.0-alpha.1 |
|
I experienced the same issue and manually specifying the defaultValue of nil did fix it. But digging into it I'm not sure why that's the case. Without specifying the defaultValue, the convenience init should be calling the private init which sets the defaultValue to nil
so functionally both inits should be equivalent. Further, the subscript function uses the nil coalescing operator to run through possible return values
the
So I'm not sure why the nil coalescing would ever return the specified nil defaultValue instead of the empty string. |
Hey guys. Indeed this is a bug. The problem came from the new "default values" protocols. We'll be removing them in a new alpha. Sorry for that. |
This is my definition, please note the Optional type:
And this is how I'm storing my value:
Defaults[.myValue] = newValue
And this is me talking to llvm:
Expected result: Defaults[.myValue] is nil
Version: 4.0.0-alpha.1
Installed via CocoaPods
The text was updated successfully, but these errors were encountered: