Hi
I have a singleton which I hold a single integer in, my score. However when I load it form the singleton in a another view it doesn't show what I want but instead sticks at a wired 6592960. Any ideas why? Something to do with how I am using @property Im thinking, what the correct way to @property an int?
Thanks.
EDIT: Code: Singleton .h
#import <Foundation/Foundation.h>
@interface scoreData : NSObject {
int score;
}
@property int score;
+ (scoreData *)sharedData;
@end
Singleton .m
#import "scoreData.h"
static scoreData *sharedData = nil;
@implementation scoreData
@synthesize score;
#pragma mark -
#pragma mark Singleton Methods
+ (scoreData *)sharedData {
if(sharedData == nil){
sharedData = [[super allocWithZone:NULL] init];
}
return sharedData;
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedManager] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (unsigned)retainCount {
return NSUIntegerMax;
}
- (void)release {
//do nothing
}
- (id)autorelease {
return self;
}
@end
Inside my other view, I access like this and then try and change the number and of course I import the singleton:
scoreData *score = [scoreData sharedData];
score.score = 0;