Coleman Beiler
Coleman Beiler

Reputation: 15

Extending in SKSpriteNode in swift

Basically this is very simple. I want to extend SKSpriteNode with just one variable. I want it to be a variable number 1 through 8 that i can check against another global var. The problem is, when I do an extension of SKSpriteNode and make a var like thisColor, it says that "extensions may not store properties" Can anyone help me solve this problem???

Thanks!

Upvotes: 0

Views: 292

Answers (1)

Beau Nouvelle
Beau Nouvelle

Reputation: 7252

The error is kind of telling you all that you need to know.

The only properties that extensions support are those that are computed. Which is essentially the same as using a function.

There's no way around this.

For example:

extension SKSpriteNode {

    var randomNumber: Int { return Int(arc4random_uniform(10)) }

}

Upvotes: 1

Related Questions