5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SpriteKitを試してみる7 swift1.2での変更点(init)

Last updated at Posted at 2015-04-14

swift1.2になったら文法が色々変更されましたが、中でもSKSpriteNodeのサブクラスでのinitの宣言の変更点はちょっと特徴的です。

1.2以前
class A: SKSpriteNode {
    
}

class B: A {
    override init(){
    	let texture = SKTexture(imageNamed: "sample.png")
    	super.init(texture: texture, color: nil, size: texture.size())
    }
    
        required override init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
1.2
class A: SKSpriteNode {
    
}

class B: A {
    init(){ //<- overrideが不要
    	let texture = SKTexture(imageNamed: "sample.png")
    	super.init(texture: texture, color: nil, size: texture.size())
    }
    
    required  init(coder aDecoder: NSCoder) { //<- overrideが不要
        fatalError("init(coder:) has not been implemented")
    }
}

親クラスでinitを宣言してない場合、override修飾子が不要になったようです。
ちなみにこれはSKSpriteNodeだけなのでUIViewのサブクラスでは必要。
どうしてこうなったのかまではまだ分かりません。
いずれ分かればこちらに追記したいと思います。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?