只是想对该代码进行完整性检查,以存储和检索 iOS 7 的用户数据。它不起作用,但我没有看到问题。
游戏数据.h
#import <Foundation/Foundation.h>
@interface GameData : NSObject<NSCoding>
{
int HighScoreGD;
}
@property (readwrite,assign) int HighScoreGD;
@end
extern GameData *gGameData;
游戏数据.m
#import "GameData.h"
GameData *gGameData;
@implementation GameData
@synthesize HighScoreGD;
-(void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInt:HighScoreGD forKey:@"HighScoreGD"];
}
-(id)initWithCoder:(NSCoder *)coder {
if((self = [super init])) {
HighScoreGD = [coder decodeIntForKey:@"HighScoreGD"];
}
return self;
}
-(id) init {
if((self = [super init])) {
}
return self;
}
-(void) dealloc {
//[super dealloc];
}
@end
存储数据:
gGameData.HighScoreGD = pointsHigh;
检索数据:
pointsHigh = gGameData.HighScoreGD;
我过去曾在一堆旧游戏概念(cocos2d)中使用过它,并且效果很好。
没有得到编译错误。只是不存储数据。
我已经有几年没有使用过这段代码了,而且它不起作用。iOS7 或 cocos2d v3 是否改变了 NSCoder 的使用方式?
还是我在某个地方犯了一个愚蠢的错误?
提前致谢。