Since the update from Swift 2.3 to 3.0 my localiser class stopped working. I pin pointed the problem and it is do to my injection of a string into another string. However, I can't figure out why this is happening.
So what happens is that I insert an non optional string into a string. When I print out this string, it is shown as optional.
Example for playground:
open class SettingsFormItem: NSObject {
/
open fileprivate(set) var title: String! = "monkey"
}
let sfi = SettingsFormItem()
func setupWithSettingsFormItem(_ settingsFormItem: SettingsFormItem) {
let test = "SETTINGS_FIELD_\(settingsFormItem.title)"
let testThatIsCorrect = "SETTINGS_FIELD_\(settingsFormItem.title!)"
print("Incorrect: \(test)")
print("Correct: \(testThatIsCorrect)")
}
setupWithSettingsFormItem(sfi)Result:
Incorrect: SETTINGS_FIELD_Optional("monkey")
Correct: SETTINGS_FIELD_monkeyAs you can see, both test is non-optional as well as the var title in class SettingsFormItem, so why does the print show SETTINGS_FIELD_Optional("monkey")? If I force unwrap settingsFormItem.title! it does work.