J.Doe
J.Doe

Reputation: 1552

How to do pointers in swift like I used to do in c++

So apple has had very little documentation I can find for doing this. The big feature I miss from c++ is being able to do something like this (Sorry for any syntax errors I am a little rusty in c++

Int* Chosenint;
Int option1 = 1
Int option2 = 2
Int option3 = 3

if (the sun is up)
    Chosenint = &option1
else
    Chosenint = &option2

However swift doesnt recognize the "*" or the "&" operator. All I am trying to do is have a global variable that stores a pointer to a SKSpriteNode, and can change to a different one. All swift seems to have is the large UnsafeMutablePointer thing. So how would you do that c++ code in swift but with skspritenodes?

Upvotes: 0

Views: 269

Answers (1)

MirekE
MirekE

Reputation: 11555

All I am trying to do is have a global variable that stores a pointer to a SKSpriteNode, and can change to a different one. All swift seems to have is the large UnsafeMutablePointer thing. So how would you do that c++ code in swift but with skspritenodes?

SKSpriteNode is a class, i.e. reference type, so you don't need to do anything. You get the behavior without asterisks and ampersands.

Upvotes: 2

Related Questions