GCD VS. NSOperationQueue
Gcd Vs Nsoperationqueue
1. GCDの利点:GCDの実装は低レベルで、より軽量です。また、NSOperationは、より複雑でヘビー級の文法です。
- NSOperationの利点:
1.制御性
NSOperationの操作を一時停止、キャンセル、再開します。
2、依存性
に反映されます。2つの操作に依存関係を設定した場合、操作は依存関係がtrueの場合にのみ実行されます。
3、ステータス検出
に反映されます:操作または操作キューのステータスは、準備完了、実行済み、または終了として監視できます。
4.操作キューの最大数
操作の最大数を設定できます。
GCDVSの選び方。 NSOperation?
ゴールデンルール:操作のキューをより細かく制御する必要がある場合は、NSOperationを選択します。単純な操作が必要な場合(バックグラウンドスレッドにカットして一般的でない操作を実行する場合など)も使用することをお勧めします。大胆にGCD。
NSOperation and NSOperationQueue are Objective-C classes. NSOperationQueue is objective C wrapper over GCD. If you are using NSOperation, then you are implicitly using Grand Central Dispatch. GCD advantage over NSOperation: i. implementation For GCD implementation is very light-weight NSOperationQueue is complex and heavy-weight NSOperation advantages over GCD: i. Control On Operation you can Pause, Cancel, Resume an NSOperation ii. Dependencies you can set up a dependency between two NSOperations operation will not started until all of its dependencies return true for finished. iii. State of Operation can monitor the state of an operation or operation queue. ready ,executing or finished iv. Max Number of Operation you can specify the maximum number of queued operations that can run simultaneously When to Go for GCD or NSOperation when you want more control over queue (all above mentioned) use NSOperation and for simple cases where you want less overhead (you just want to do some work 'into the background' with very little additional work) use GCD
NSOperationとNSOperationQueueは、OCベースのAPIクラスです。
NSOperationQueueは、GCDのOC構文ラッパーです。 NSOperationを使用する場合、GCDは間接的に使用されます。