Confused
Confused

Reputation: 6278

Access array in GameScene from SKSpriteNode class instance?

I've created an array in my GameScene instance, and populated it inside didMove(to view: )...

From an instance of an SKSpriteNode, how do I access a value in that array?

So far as I know, from the template, I don't have a reference to the GameScene instance. But I could be way off on this, too.

Upvotes: 1

Views: 193

Answers (1)

Mark Brownsword
Mark Brownsword

Reputation: 2307

While the answer you've linked to will solve your problem, it introduces a coupling between the node and the scene which you might regret later. A more robust solution would allow the node to reference whatever scene it happens to be running in, which is a common design pattern in iOS called delegate pattern.

Upvotes: 2

Related Questions