As the title says I'm trying to append text to an implicitly unwrapped optional String via += operator which gives me
'String!' is not identical to 'UInt8' To let you see what I mean:
var myString: String = "Hello " myString += "world" // works great var myOptionalString: String! = "Foo " myOptionalString += " bar" // error: String! is not identical to 'UInt8' however if I append it while the assignment it works
var myOptionalString: String! = "Foo " myOptionalString = myOptionalString + " bar" // works great can anyone tell me the reason for that, or is there something I missed in optionals?
Update
mySecondOpString: String? = "Hello " mySecondOpString! += "world" // works great too
x+=yis not semantically equivalent tox = x+y. In the first case you have something like append y to x (x pointing to a mutable string), and in the second you have catenate x and y, and associate the result to x. Optional may change things when append...