I’ve a dictionary that may have String
or Int
values.
I take away the nil values with compactMapValues
.
One of many String values is capitalized
.
To sum it up, here is how my code seems to be :
let someOptional: Int? = nil
let take a look at: [AnyHashable: Any] = [
"Some optional" : someOptional,
"Some capitalized string" : "(true != false)".capitalized
].compactMapValues { $0 }
And after I entry the second worth :
take a look at["Some capitalized string"]!
I get this : (Operate)
, as an alternative of True
.
I assume it is as a result of capitalized
can be a way and Dictionary
in all probability takes the tactic kind over the var kind.
However why ? And the way can I pressure it to take the var
as an alternative of the func
?
The one answer I discovered was so as to add as String
after capitalized
, however I discover it bizarre that I would like to do that..