我目前正在制作一个iOS平等游戏 的教程。你可以找到this one here。Swift语法更新?协议中不允许类。无法填写SKTexture
我刚开始编码雨燕因为很多语法错误与辅导3个月内有洁癖工作时 我问我自己是否有在斯威夫特一些主要更新最近 出现。
到现在为止,我自己或自己的XCode设法解决这些小问题,但 我不能帮助自己这一点:
protocol TextureObject {
class var sharedInstance: TextureDroid {get}
var texturesIso:[[SKTexture]?] {get}
var textures2D:[[SKTexture]?] {get}
}
这是我正在尝试设置(酷似教程协议),但XCode不会让我定义类变量。错误代码是下面的:
"Class properties are only allowed within classes:
use static to declare a static property"
两个取代“类”到“静态”(这使得没有逻辑意义的我)和 删除协议(和定义应该在不使用的继承类协议),导致另一个错误在此代码:出现在所有我想要填补texturesIso
Immutable value 'self.texturesIso' may not be assigned to
这里是线
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)),
]
这个错误我问题:
如何解决第一个错误?有没有一种新的方法来定义协议内的类?
这两个错误是连接的还是第二个出现,因为我设法消除第一个?
如何以正确的方式填充SKTexture? texturesIso.append也不起作用。
我对Swift Update了吗?如果是,是否有关于Swift所有突然变化的概述,因为我找不到一个。
我真的很感激任何人的帮助,非常感谢提前。
谢谢,这个问题的答案帮助了很多 –