여기에 이상한 문제가 있습니다. Sprite Kit에서 게임을 만들고 있는데, 처음에는 모든 변수를 초기화 할 때 정상적으로 작동하는 것 같습니다. 나는 게임에서 사용할 모든 데이터를 담고있는 싱글 톤 클래스를 가지고있다. 이 싱글 톤은 하나의 객체 (World)를 보유하고 World 객체는 게임 전체에서 사용하는 객체 배열을 보유합니다.iPhone 시뮬레이터가 NSLog에서 멈춤
초기화 후 World 개체가 어떤 배열에 포함되어 있는지 인쇄 해 봅니다. 아래 예가 있습니다 :
NSLog(@"Game manager ports: %@", [IPGameManager sharedGameData].world.ports);
그러나이 기능을 실행하면 시뮬레이터가 멈 춥니 다. 나는 실제 장치에서 아직 시도하지 않았습니다 (아직 개발자 계정이 없습니다). 그러나, '포트'를 초기화 한 직후에 똑같은 것을 인쇄하면 잘 인쇄됩니다. 나는 '유지'또는 무엇이든이를 야기하지만 문제가 무엇인지 확실하지 않다 생각하지 것이다
@interface IPWorld : NSObject <NSCoding>
@property (nonatomic, retain) IPPlayer* player;
@property (nonatomic, retain) NSMutableArray* ports;
@property (nonatomic, retain) NSMutableArray* crewMembers;
@property (nonatomic, retain) NSMutableArray* ships;
@property (nonatomic, retain) NSMutableArray* quests;
@end
다음은 세계 객체의 헤더 파일입니다. 어떤 도움이라도 대단히 감사합니다. 감사!
편집 : 다음은 내 싱글의 코드입니다 :
+(instancetype)sharedGameData {
NSLog(@"Loading sharedGameData");
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSLog(@"should only see this once");
sharedInstance = [self loadInstance];
});
return sharedInstance;
}
+(instancetype)loadInstance {
NSData* decodeData = [NSData dataWithContentsOfFile:[IPGameManager filePath]];
if (decodeData) {
IPGameManager* gameData = [NSKeyedUnarchiver unarchiveObjectWithData:decodeData];
return gameData;
}
return [[IPGameManager alloc] init];
}
+(NSString*)filePath {
static NSString* filePath = nil;
if (!filePath) {
filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"gamedata"];
}
return filePath;
}
pls 충돌 메시지 게시 – Woodstock
충돌이 없습니다. 그냥 달려있다. – SpellChucker
'- [IPGameManager init]'메서드에서 흥미로운 것 (즉, 간단한 인스턴스 변수 지정을 넘어서는)이 있습니까? – Chuck