Can't access an array that's buried in a structure

I have a structure that houses some global variables. As you can see from my debugger screenshot, myGV has a variable to guessBar (a subclass of SKSpriteNode). Within that subclass it holds an array of guessSlots (another subclass of SKSpriteNode).

What bothers me, is that I can't figure out the syntax for accessing that array from myGV. From the debugger you can see the array from myGV, but from the highlighted line, I can't seem to access the array, even though it is visible in the debugger.

Any thoughts?

Is the type of myGV.guessBar SKSpriteNode or SKSpriteNode?. If it's an optional, you need to unwrap it before trying to access its properties. Use myGV.guessBar?.guessSlots to get an optional array or force unwrap it with myGV.guessBar!.guessSlots to get the array.

No, that wasn't it....but something you said snapped my attention to the declaration of myGV.

I had

struct GlobalVars{
    var guessBar        : SKSpriteNode?

instead of:

struct GlobalVars{
    var guessBar        : GuessBar?

I am so embarrassed

Terms of Service

Privacy Policy

Cookie Policy