vendredi 27 mars 2015

Why isn't is possible to append a String! via += operator?

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?


Aucun commentaire:

Enregistrer un commentaire