0

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.

1 Answer 1

1

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?
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.