2013-04-27 97 views
0

我正在寫一個基於回合的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 =零似乎沒有工作,也不認爲:

[matchData isEqualToData:[NSData alloc]] 

任何想法?

回答

0
if (!matchData || (matchData.length==0)) 
相關問題