5
枚舉,通過快速枚舉,通過[NSOperationQueue operations]
安全嗎?像這樣:枚舉[NSOperationQueue操作]是否安全?
for (NSOperation *op in [operationQueue operations]) {
// Do something with op
}
由於操作是異步的,在另一個線程執行,operations
可以隨時更改(包括主線程的執行期間)。快速枚舉可以防止這種情況,還是我應該使用操作數組而不是copy
(和autorelease
)?
+1,很好的從文檔中捕獲 –
的確,非常好的捕獲。謝謝彼得。 –