2014-04-21 70 views
0

我正在使用Parse進行數據存儲。我創建自己的遊戲查詢打開得分這在回調返回數組是這樣的:如何將結果的NSArray迭代到單獨的數組中

(
"<GameTurnScore:ipPd3tKRc1:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 1;\n TurnDifficulty = 0;\n TurnNumber = 1;\n TurnScore = 500;\n UserRef = \"<PFUser:e3Wyo4JaKC>\";\n}", 
"<GameTurnScore:AendjA9Yzq:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 6;\n TurnDifficulty = 1;\n TurnNumber = 2;\n TurnScore = 48;\n UserRef = \"<PFUser:UgkZDtDsVC>\";\n}", 
"<GameTurnScore:ZTNmSkGae1:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 8;\n TurnDifficulty = 2;\n TurnNumber = 3;\n TurnScore = 60;\n UserRef = \"<PFUser:e3Wyo4JaKC>\";\n}", 
"<GameTurnScore:8QbcznSa1u:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 3;\n TurnDifficulty = 1;\n TurnNumber = 4;\n TurnScore = 99;\n UserRef = \"<PFUser:UgkZDtDsVC>\";\n}", 
"<GameTurnScore:Mj6LmdE5LY:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 8;\n TurnDifficulty = 0;\n TurnNumber = 5;\n TurnScore = 60;\n UserRef = \"<PFUser:e3Wyo4JaKC>\";\n}", 
"<GameTurnScore:qeDWt7KFK2:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 12;\n TurnDifficulty = 1;\n TurnNumber = 6;\n TurnScore = 24;\n UserRef = \"<PFUser:UgkZDtDsVC>\";\n}", 
"<GameTurnScore:RMRYi9fkUu:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 1;\n TurnDifficulty = 2;\n TurnNumber = 7;\n TurnScore = 500;\n UserRef = \"<PFUser:e3Wyo4JaKC>\";\n}", 
"<GameTurnScore:Fd78iI8NGo:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 6;\n TurnDifficulty = 1;\n TurnNumber = 8;\n TurnScore = 48;\n UserRef = \"<PFUser:UgkZDtDsVC>\";\n}", 
"<GameTurnScore:qioVUqmbEB:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 1;\n TurnDifficulty = 2;\n TurnNumber = 9;\n TurnScore = 500;\n UserRef = \"<PFUser:e3Wyo4JaKC>\";\n}", 
"<GameTurnScore:iFLS39GqLM:(null)> {\n GameRef = \"<Game:jGBok5ZiXM>\";\n TotalGuesses = 1;\n TurnDifficulty = 1;\n TurnNumber = 10;\n TurnScore = 300;\n UserRef = \"<PFUser:UgkZDtDsVC>\";\n}" 
) 

然後我需要這些分數分成兩個獨立的數組。目前我基於用戶分開,但我想根據TurnNumber分開它們。

我不確定的具體部分是如果轉彎號不存在,則將一個emtpy索引或[NSNull null]插入索引。

例如,我有兩個新的NSArrays調用scoreBlock1scoreBlock2。如果缺少第3輪,我想在scoreBlock1以下。

turnNumber1
NSNull空
turnNumber5
turnNumber7
turnNumber9

什麼是迭代結果數組實現這一目標的最佳方式是什麼?

+0

空值的存在,爲什麼你要到位失蹤圈空值?似乎只是讓他們失蹤會更容易處理。另外,你如何「知道」缺少一個轉身? – CrimsonChris

+0

謝謝,我想原因是我知道每個索引中有一個對象。如果我只是添加任何轉到新數組我如何檢查索引中是否有對象? – StuartM

回答

0

您可以使用[array addObject:[NSNull null]]將空值插入到數組中。

將來可以測試使用[object isKindOfClass:[NSNull class]]

+0

謝謝,我知道我可以使用'valueForKey ...'和'objectForKey'來檢索我需要的值。問題更多的是圍繞如何處理缺少特定轉折分數以及在那裏插入空值。 – StuartM

+0

如果您使用valueForKeyPath的切片變體,它會將NSNull放入缺少的值中,這就是我解釋您的請求的方式。如果您不打算切片數組,但只想查找缺失的分數,則可能需要查看filteredArrayUsingPredicate和predicate TurnNumber = nil。 –

+0

如果你想在for循環中建立兩個結果數組,你可以使用'addObject:[NSNull null]' –

相關問題