views:

83

answers:

1

I have been attempting to have a object that I can use across multiple view controllers by following this thread.

http://stackoverflow.com/questions/851158/one-instance-across-multiple-views

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.

+1  A: 

Couple of possibly silly questions:

  1. Does [PlayerData init] initialise your property to zero?
  2. Does your UIViewController alloc/init the PlayerData object before you try to increment it?
Stephen Darlington
That was it. I thought since the values were not even 0 that might be a problem but I was think the @synthesize should have done that.
Aaron