Reputation: 252
I have been attempting to have a object that I can use across multiple view controllers by following this thread.
One instance across multiple views in Cocoa Touch
But it has not been working 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 inspect this in the debugger and I see 0 for all values when I create it and then it gets updated by the appropriate line of code so I feel like my object class is written correctly.
When I try to define the object in my header file to like this:
In my UIViewController.h I added the following
#import "PlayerData.h"
PlayerData *playerOne;
@property (nonatomic, retain) PlayerData *playerOne;
In my UIViewContoller.m I have added the following
#import "PlayerData.h"
@synthesize playerOne;
playerOne.completedRound += 1;
I cannot get it to work. The code compiles fine but viewing the instance in the debugger non of the variable ever get set.
Upvotes: 0
Views: 210
Reputation: 52565
Couple of possibly silly questions:
[PlayerData init]
initialise your property to zero?UIViewController
alloc
/init
the PlayerData
object before you try to increment it?Upvotes: 1