Open orj opened 1 year ago
I have noticed in extension UserDefaults: FlagValueSource
method setFlagValue<Value>()
that value
is a ApplicationUserMode??
(note the double optional). The outer optional is non-nil as it contains the inner nil. So the initial guard let value = value
passes but when attempting to insert the value.boxedFlagValue
it resolves to nil.
Perhaps I'm holding it wrong?
I note that if I make the enum
CaseIterable
it doesn't crash. But the editor is a bit "meh" and doesn't work quite right.
https://github.com/unsignedapps/Vexil/assets/34415/dfcf743e-dde1-462c-ad86-053f9ad53bd6
I feel like the last problem could perhaps be addressed or improved by https://github.com/unsignedapps/Vexil/pull/112
Pretty sure the crash occurs here: https://github.com/unsignedapps/Vexil/blob/6b8a039d4fffe105b717b08df3e8eb6b588e0ea3/Sources/Vexil/Sources/UserDefaults%2BFlagValueSource.swift#L43-L51
One way to stop the crash would be to use nil
when .boxedFlagValue.object == NSNull()
:
if value.boxedFlagValue.object == NSNull() {
set(nil, forKey: key)
} else {
set(value.boxedFlagValue.object, forKey: key)
}
This doesn't quite work for setting optional values though. It simply removes the flag rather than setting it to nil
. Using Data()
instead of nil
could be an option. I'm not 100% on how UserDefaults differs across platforms and not too familiar with Vexil
so opted to leave it out of #112.
A small change to OptionalCaseIterableFlagControl
would also be needed.
@orj Here's a branch with the above changes. Any chance you could give it a test drive and make sure it doesn't break anything else? I was only testing with an optional case iterable control too. https://github.com/unsignedapps/Vexil/compare/main...patANZx:Vexil:fix/vexillographer-optional-flags
I have noticed in extension UserDefaults: FlagValueSource method setFlagValue
() that value is a ApplicationUserMode?? (note the double optional). The outer optional is non-nil as it contains the inner nil. So the initial guard let value = value passes but when attempting to insert the value.boxedFlagValue it resolves to nil.
@orj Oh I missed this message. Didn't realise you had already figured it out :P Not sure if the above fix is suitable but it's been working okay with the OptionalCaseIterableFlagControl
for me.
The double-optional problem is something I also encountered but never bothered to investigate: https://github.com/unsignedapps/Vexil/pull/109 so if deemed suitable your solution would fix a few
@huwr I'm guessing some more work would need to be done with the text editor to get it working fully. I haven't used it much but I remember having a hard time with optional numbers.
Optional
enum
flags seem to Crash Vexilographer when going into edit mode.Vexil version:
2.2.1
Swift version:swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Environment: Version 14.3.1 (14E300c)✅ Checklist
- [ ] If possible, I've reproduced the issue using themain
branch of this package🔢 Steps to Reproduce
Replace this paragraph with an explanation of how to reproduce the incorrect behavior. This could include a code listing for a reduced version of your command, or a link to the code that is exhibiting the issue.
🎯 Expected behavior
No crash. Things work as expected.
🕵️♀️ Actual behavior
I have defined a flag like this:
The
ApplicationUserMode
is defined as:When trying to edit this in Vexilographer it crashes with the following stack trace.