I'm currently working on a tutorial for creating an iOS Isometric Game. You can find this one here.
I just started coding Swift and because a lot of Syntax errors appeared while working with tutorials a little older than 3 months I asked my self if there were some main updates in Swift lately.
Until now, myself or XCode itself managed to fix those little issues, but I cant help myself with this:
protocol TextureObject {
class var sharedInstance: TextureDroid {get}
var texturesIso:[[SKTexture]?] {get}
var textures2D:[[SKTexture]?] {get}
}
This is the protocol I'm trying to set (exactly like in the tutorial), but XCode won't let me define the class variable. The error code is the following:
"Class properties are only allowed within classes:
use static to declare a static property"
Both replacing "class" to "static" (which makes no logical sense to me) and deleting the protocol (and define the class that should inherit without the use of the protocol) lead to another error in this code:
class TextureDroid: TextureObject {
class var sharedInstance: TextureDroid {
return textureDroid
}
let texturesIso:[[SKTexture]?]
let textures2D:[[SKTexture]?]
init() {
texturesIso = [[SKTexture]?](count: 2, repeatedValue: nil)
textures2D = [[SKTexture]?](count: 2, repeatedValue: nil)
//Idle
texturesIso[Action.Idle.rawValue] = [
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.N, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.NE, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.E, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.SE, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.S, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.SW, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.W, Action.Idle)),
SKTexture(imageNamed: "iso_3d_"+textureImage(Tile.Droid, Direction.NW, Action.Idle)),
]
This error appears in all the lines where I want to fill the texturesIso
Immutable value 'self.texturesIso' may not be assigned to
Here are my questions:
How can I fix the first error? Is there a new way to define classes inside a protocol?
Are those two errors connected, or is the second just appearing, because i managed to eliminate the first?
How can I fill the SKTexture in the right way? texturesIso.append won't work either.
Am I right with the Swift Update? If yes, is there an overview of all the sudden changes to Swift, because I could'n find one.
I would really appreciate anyone's help, thanks a lot in advance.