swift - Add String to variable -
i have variable let name = ["pete"] , want add second name it.
name array, add element can use append. you'll need make name variable though:
// note - `name` declared `var` instead of `let` var name = ["pete"] name.append("anothername") println(name) // ["pete", "anothername"] (if you're unfamiliar arrays recommend take @ the swift programming language: collection types.)
the naming of variable suggests didn't intend array though. in case wanted string, do:
var name = "pete" name += " secondname" println(name) // pete secondname
Comments
Post a Comment