When you retrieve a value from such a dictionary using an index
[String: String?]
you need to manage two levels of optional. The first one is because the index returns optional. Second, because the meaning of your dictionary is an optional string.
So when you write
if let value = preferenceSpecification["someKey"] { }
you get a value defined as an optional string.
Here is the code to fix that
if let optionalKey = preferenceSpecification["Key"], key = optionalKey, optionalDefaultValueKey = preferenceSpecification["DefaultValue"], defaultValueKey = optionalDefaultValueKey, value = preferenceSpecification[defaultValueKey] { defaultsToRegister[key] = value }
suggestions
- You should avoid forced deployment. Instead, you managed to post 3
! on one line! - You should also try to use a better name for your constants and variables.
Luca Angeletti Aug 18 '16 at 19:58 2016-08-18 19:58
source share