我正在编写基于回合制的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]]
有什么想法吗?
答案 0 :(得分:0)
if ( !matchData || (matchData.length==0) )