Using an object across multiple view controllers

I am trying to create an object that I can use for multiple view controllers by following this thread.

One copy for several species in Cocoa Touch

But it didn't work for me. So I started with the basics to see what was going on. I created a local instance of the object.

PlayerData *playerOne   = [[PlayerData alloc] init];
playerOne.completedRound += 1;

      

I can test this in the debugger and I see 0 for all values ​​when I create it, and then it is updated with the appropriate line of code, so I feel like my object class is written correctly.

When I try to define an object in my header file like so:

In my UIViewController.h, I added the following

#import "PlayerData.h"

PlayerData *playerOne;

@property (nonatomic, retain) PlayerData *playerOne;

      

In my UIViewContoller.m I added the following

#import "PlayerData.h"

@synthesize playerOne;

playerOne.completedRound += 1;

      

I cannot get it to work. The code compiles fine, but views the instance in the debugger with no variable ever getting.

0


a source to share


1 answer


Several possible silly questions:



  • Does [PlayerData init]

    your property roll out to zero?
  • Does your object UIViewController

    alloc

    / init

    object represent PlayerData

    before enlarging it?
+1


a source







All Articles