我的情況,我必須遍歷賬號列表,去獲取這些帳戶的詳細信息,然後通過彙總信息completionBlock被調用。爲了促進這一點,我使用dispatch_group_ *方法。不幸的是,在完成塊被稱爲之前,該集團已經完成了,即使我已經明確調用控制檯日誌的我如何確保調度通知在正確的時間
dispatch_group_wait(_imfDispatchGroup, DISPATCH_TIME_FOREVER);
例(原件):
2012-10-28 13:58:46.722 ThreadingHell[81909:303] inside loginResponse
2012-10-28 13:58:46.724 ThreadingHell[81909:303] inside account loop for obj: account1
2012-10-28 13:58:46.724 ThreadingHell[81909:303] inside account loop for obj: account2
2012-10-28 13:58:46.724 ThreadingHell[81909:1b03] inside details: L0i6kRVzGG details
2012-10-28 13:58:46.724 ThreadingHell[81909:1a03] inside details: SE0QjhO8Hh details
2012-10-28 13:58:46.724 ThreadingHell[81909:303] inside account loop for obj: account3
2012-10-28 13:58:46.725 ThreadingHell[81909:1a03] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_015
2012-10-28 13:58:46.725 ThreadingHell[81909:1803] inside details: 9SsGYOX3u5 details
2012-10-28 13:58:46.725 ThreadingHell[81909:1a03] details are found for account
2012-10-28 13:58:46.725 ThreadingHell[81909:303] inside account loop for obj: account4
2012-10-28 13:58:46.725 ThreadingHell[81909:1b03] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_015
2012-10-28 13:58:46.726 ThreadingHell[81909:1803] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_015
2012-10-28 13:58:46.726 ThreadingHell[81909:303] inside account loop for obj: acount5
2012-10-28 13:58:46.726 ThreadingHell[81909:1a03] success account looop
2012-10-28 13:58:46.726 ThreadingHell[81909:1b03] details are found for account
2012-10-28 13:58:46.726 ThreadingHell[81909:2303] inside details: wSXis5bIVs details
2012-10-28 13:58:46.728 ThreadingHell[81909:1803] details are found for account
2012-10-28 13:58:46.728 ThreadingHell[81909:2403] inside details: SrIfbzBLr7 details
2012-10-28 13:58:46.728 ThreadingHell[81909:1a03] current instance of accountDetails: ( "L0i6kRVzGG details")
2012-10-28 13:58:46.728 ThreadingHell[81909:1803] success account looop
2012-10-28 13:58:46.728 ThreadingHell[81909:1b03] success account looop
2012-10-28 13:58:46.729 ThreadingHell[81909:2403] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_015
2012-10-28 13:58:46.729 ThreadingHell[81909:303] !!!!!!!!!! about to call completion block. This should be last
2012-10-28 13:58:46.729 ThreadingHell[81909:2303] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_015
2012-10-28 13:58:46.730 ThreadingHell[81909:1803] current instance of accountDetails: ( "L0i6kRVzGG details", "9SsGYOX3u5 details")
2012-10-28 13:58:46.730 ThreadingHell[81909:1b03] current instance of accountDetails: ( "L0i6kRVzGG details", "9SsGYOX3u5 details", "SE0QjhO8Hh details")
2012-10-28 13:58:46.731 ThreadingHell[81909:2403] details are found for account
2012-10-28 13:58:46.731 ThreadingHell[81909:2303] details are found for account
2012-10-28 13:58:46.732 ThreadingHell[81909:2403] success account looop
2012-10-28 13:58:46.731 ThreadingHell[81909:303] obj: { }
2012-10-28 13:58:46.732 ThreadingHell[81909:2303] success account looop
2012-10-28 13:58:46.732 ThreadingHell[81909:303] error: (null)
2012-10-28 13:58:46.732 ThreadingHell[81909:2403] current instance of accountDetails: ( "L0i6kRVzGG details", "9SsGYOX3u5 details", "SE0QjhO8Hh details", "wSXis5bIVs details")
//修訂從LOG最新提交[https://github.com/kwylez/ThreadingHell/tree/80cc29fab142b4dc1f386df747c5142b28e2dd84]
2012-10-28 16:32:38.984 ThreadingHell[83171:303] inside loginResponse 2012-10-28 16:32:38.987 ThreadingHell[83171:303] inside account loop for obj: account1 2012-10-28 16:32:38.987 ThreadingHell[83171:303] inside account loop for obj: account2 2012-10-28 16:32:38.987 ThreadingHell[83171:1b03] inside details: CP3ioYdvXp details 2012-10-28 16:32:38.987 ThreadingHell[83171:303] inside account loop for obj: account3 2012-10-28 16:32:38.987 ThreadingHell[83171:1a03] inside details: 6k635XoJOV details 2012-10-28 16:32:38.987 ThreadingHell[83171:1b03] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_0 2012-10-28 16:32:38.988 ThreadingHell[83171:1a03] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_0 2012-10-28 16:32:38.988 ThreadingHell[83171:1b03] details are found for account 2012-10-28 16:32:38.988 ThreadingHell[83171:303] inside account loop for obj: account4 2012-10-28 16:32:38.988 ThreadingHell[83171:1803] inside details: 2TjGF1fdaZ details 2012-10-28 16:32:38.989 ThreadingHell[83171:1a03] details are found for account 2012-10-28 16:32:38.990 ThreadingHell[83171:1b03] success account looop 2012-10-28 16:32:38.991 ThreadingHell[83171:1b03] current instance of accountDetails: ( "CP3ioYdvXp details") 2012-10-28 16:32:38.990 ThreadingHell[83171:303] inside account loop for obj: acount5 2012-10-28 16:32:38.990 ThreadingHell[83171:2303] inside details: 0YiuX9gHsu details 2012-10-28 16:32:38.990 ThreadingHell[83171:1a03] success account looop 2012-10-28 16:32:38.990 ThreadingHell[83171:1803] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_0 2012-10-28 16:32:38.992 ThreadingHell[83171:2303] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_0 2012-10-28 16:32:38.992 ThreadingHell[83171:1b03] inside details: 9RcyOfjRa5 details 2012-10-28 16:32:38.992 ThreadingHell[83171:1a03] current instance of accountDetails: ( "CP3ioYdvXp details", "6k635XoJOV details") 2012-10-28 16:32:38.992 ThreadingHell[83171:1803] details are found for account 2012-10-28 16:32:39.005 ThreadingHell[83171:1803] success account looop 2012-10-28 16:32:39.005 ThreadingHell[83171:1b03] inside completion for __66-[ModelManager getAccountDetailsForAccountNumber:completionBlock:]_block_invoke_0 2012-10-28 16:32:39.005 ThreadingHell[83171:2303] details are found for account 2012-10-28 16:32:39.006 ThreadingHell[83171:1b03] details are found for account 2012-10-28 16:32:39.006 ThreadingHell[83171:2303] success account looop 2012-10-28 16:32:39.006 ThreadingHell[83171:1803] current instance of accountDetails: ( "CP3ioYdvXp details", "6k635XoJOV details", "2TjGF1fdaZ details") 2012-10-28 16:32:39.007 ThreadingHell[83171:1b03] success account looop 2012-10-28 16:32:39.007 ThreadingHell[83171:2303] current instance of accountDetails: ( "CP3ioYdvXp details", "6k635XoJOV details", "2TjGF1fdaZ details", "0YiuX9gHsu details") 2012-10-28 16:32:39.008 ThreadingHell[83171:1b03] current instance of accountDetails: ( "CP3ioYdvXp details", "6k635XoJOV details", "2TjGF1fdaZ details", "0YiuX9gHsu details", "9RcyOfjRa5 details") 2012-10-28 16:32:39.008 ThreadingHell[83171:303] !!!!!!!!!! about to call completion block. This should be last 2012-10-28 16:32:39.009 ThreadingHell[83171:303] obj: { } 2012-10-28 16:32:39.009 ThreadingHell[83171:303] error: (null)
我錯過了什麼「操作順序」?
這裏是鏈接到示例項目在GitHub上(代碼是太多,放在這裏):
https://github.com/kwylez/ThreadingHell
+1爲項目名稱。 – jrturton
我更新了項目,並且已經接近了一些。所有「塊」以正確的順序進行,但最終數組在返回最終完成塊時爲空。 我編輯了新的日誌原來的問題比較 –