我正在编写一个基于回合的 iOS 游戏,现在我在检测匹配数据何时为空时遇到问题。这是我加载匹配数据的功能:
- (NSMutableArray*) loadMatchData
{
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
{
if (matches)
{
currentGames = [[NSMutableArray alloc] init];
for (int i = 0; i < matches.count; i++)
{
[(GKTurnBasedMatch*)matches[i] loadMatchDataWithCompletionHandler: ^(NSData *matchData, NSError *error)
{
if (matchData != nil)
{
Game* game = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
[currentGames addObject:game];
}
else
{
Game* game = [[Game alloc] init];
[currentGames addObject:game];
game.activePlayer = [GKLocalPlayer localPlayer];
}
}];
}
}
}];
return currentGames;
}
不幸的是, matchData != nil 似乎不起作用,也没有:
[matchData isEqualToData:[NSData alloc]]
有任何想法吗?