私は幻覚していると思います。私はConcentration-lkeゲームにいくつかの持続性を追加しようとしています。私は高い得点を記録したいと思います。私はこれを部分的に今日働いているが、今はすべてがkablooieになっている(私は正しいiOSの用語だと思う)。さて、私のallHighScores NSMutablearrayは突然CALayerになります。私はNSKeyedのアーカイブを使用しています。 allHighScoresにデータがロードされる前にファイルにブレークポイントがあります。アプリケーションをステップ実行すると、allHighScoresはNSMutableArrayとして存在し、次のステップで突然CAレイヤーになります。ハァッ?どういうわけか私のNSMutableArrayが突然CALayerになります
-(id)init
{
self = [super init];
if (self) {
NSString *path = [self flipScoreArchivePath];
NSLog(@"Path is %@", path);
allHighScores = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
if (!allHighScores) {
allHighScores = [[NSMutableArray alloc] init];
}
}
return self;
}
+(FlipHighScoreStore *)sharedStore {
static FlipHighScoreStore *sharedStore = nil;
if (!sharedStore) {
sharedStore = [[super allocWithZone:nil]init];
}
return sharedStore;
}
、CALayerのにNSMutableArrayのから私のallHighScoresを変更NSKeyedUnarchiverを呼び出します。私は非常に混乱しています。
私はアーカイブ解除命令にretainを追加しようとしましたが、それは助けになりませんでした。
-(void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.themeChosen forKey:@"themeChosen"];
[aCoder encodeInt:self.highScore forKey:@"highScore"];
[aCoder encodeInt:self.scoreStartLevel forKey:@"scoreStartLevel"];
[aCoder encodeInt:self.scoreFinishLevel forKey:@"scoreFinishLevel"];
[aCoder encodeObject:scoreDateCreated forKey:@"scoreDateCreated"];}
-(id)initWithCoder:(NSCoder *)aDecoder {
if (self) {
self.themeChosen = [aDecoder decodeObjectForKey:@"themeChosen"];
self.highScore = [aDecoder decodeIntForKey:@"highScore"];
self.scoreStartLevel = [aDecoder decodeIntForKey:@"scoreStartLevel"];
self.scoreFinishLevel = [aDecoder decodeIntForKey:@"scoreFinishLevel"];
scoreDateCreated = [aDecoder decodeObjectForKey:@"scoreDateCreated"];
}
return self;}
UPDATE:
はここに私のエンコード/デコードコードでプログラムがクラッシュ「highscores.archive」ファイルがすでに存在し、保存が再び呼び出されます。私はハイスコアを見て、アプリを起動することができます - 彼らはそこにあると喜んで取り出されますが、コードを保存:
-(BOOL)saveHighScores {
NSString *path = [self flipScoreArchivePath];
return [NSKeyedArchiver archiveRootObject:allHighScores toFile:path];}
はEXC_BAD_ACCESSを引き起こします。パスは正しいので、何とかallHighScoresはそうではありません。
ARCを使用していますか? – joerick
'FlipHighScore'でNSCodingプロトコルを実装する方法や、クラス名が何であるかを教えてください。 – mbm29414
このNSLog(@アーカイブされていないクラス%@ "、NSStringFromClass([allHighScores class]));'を試して、出力に注意してください。 – CodaFi