如何判断匹配数据是否为空?

时间:2013-04-27 00:12:14

标签: iphone ios ios6 nsdata game-center

我正在编写基于回合制的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]]

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

if ( !matchData  || (matchData.length==0) )