Reputation: 99
Getting an error "Cannot invoke 'enumerate' with an argument list of type '(String)' " when I'm following Neil North's game tutorial for iOS Swift. Is this relating to an old method of some sort in 1.2? Any ideas?
convenience init(atlasName: String, tileSize: CGSize,
tileCodes: [String]) {
self.init(tileSize: tileSize,
gridSize: CGSize(width: tileCodes[0].characters.count,
height: tileCodes.count))
atlas = SKTextureAtlas(named: atlasName)
for row in 0..<tileCodes.count {
let line = tileCodes[row]
// ERROR IS HERE
for (col, code) in enumerate(line) {
if let tile = nodeForCode(code) {
tile.position = positionForRow(row, col: col)
if tile.name == "scenery" {
tile.position = CGPoint(x: tile.position.x, y: tile.position.y - (tileSize.height/2))
}
addChild(tile)
}
}
}
}
Upvotes: 2
Views: 655
Reputation: 70109
You should call enumerate
on the collection itself. But in Swift 2 String
is not a collection anymore - it has a characters
property instead.
So to iterate over your String you should call enumerate
on the characters
property:
for (col, code) in line.characters.enumerate() {
Upvotes: 3
Reputation: 16837
Yes, String is no longer part of the collection type in swift 2.
You now want to use line.characters
For more reading on this matter, please see https://developer.apple.com/swift/blog/?id=30
Upvotes: 5