GCD is a low-level C-based API.
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:
- implementation
For GCD implementation is very light-weight
NSOperationQueue is complex and heavy-weight
NSOperation advantages over GCD:
- Control On Operation
you can Pause, Cancel, Resume an NSOperation - Dependencies
you can set up a dependency between two NSOperations operation will not started until all of its dependencies return true for finished. - State of Operation
can monitor the state of an operation or operation queue. ready ,executing or finished - 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
Ref.
https://stackoverflow.com/questions/10373331/nsoperation-vs-grand-central-dispatch
'iOS > iOS 기본기' 카테고리의 다른 글
[iOS] frame vs. bounds (0) | 2019.12.09 |
---|---|
[iOS] int vs NSInteger vs NSNumber (0) | 2019.12.05 |
[iOS] UIKit framework 계층도 (2) | 2019.11.25 |
[iOS] NSCopying protocol (0) | 2019.11.25 |
[iOS] Archive - NSCoding protocol, Serialization(직렬화), NSUserDefaults (0) | 2019.11.24 |