for loop variable name use swift -
i have static variable name want create use loop :
var imageke1 = "" var imageke2 = "" var imageke3 = "" var imageke4 = "" var imageke5 = "" var imageke6 = "" var imageke7 = ""
i try create error expected pattern:
for var = 1; < 8; i++ { var "imageke\(i)" = "" }
i try conflict same variable name (kucing) :
for var = 1; < 8; i++ { var kucing = "imageke\(i)" var kucing = "" }
at end create list of string result, , want change loop:
var names: [string] = ["\(imageke1)", "\(imageke2)", "\(imageke3)", "\(imageke4)", "\(imageke5)", "\(imageke6)", "\(imageke7)"]
how loop variable name (imageke) , var names?
var names: [string] = [] index in 1...8 { names.append("imageke\(index)") } println(names) // "[imageke1, imageke2, imageke3, imageke4, imageke5, imageke6, imageke7, imageke8]"
Comments
Post a Comment