NSOperation
来源:互联网 发布:自己做图片的软件 编辑:程序博客网 时间:2024/06/15 15:06
- Executing the Operation
- Canceling Operations
- Getting the Operation Status
- Managing Dependencies
- Configuring the Execution Priority
- Waiting on an Operation Object
NSOperation是一个任务的抽象接口,我们主要使用它的子类。也可以使用自定义的Operation,继承NSOperation即可。
NSOperation的子类有如下几种:
- CKOperation:CloudKit库中的类,主要为执行cloud操作提供操作基类。
- NSBlockOperation:以block的方式添加任务。
- NSInvocationOperation:以target的方式添加任务,swift已废弃。
- UIActivityItemProvider:UIKit库中的类,主要用于UIActivityViewController处理数据时的协议。
Subclassing Notes
对于继承NSOperation,非并发的Operation,只需实现:
- main
对于并发的Operation,需要实现如下几种方法:
- start
- asynchronous
- executing
- finished
1 Executing the Operation
/// 开始执行方法public func start()/// 执行的非并发操作public func main()/// 操作执行完毕的回调@available(iOS 4.0, *)public var completionBlock: (() -> Void)?
2 Canceling Operations
/// 取消任务public func cancel()
3 Getting the Operation Status
/// 是否取消public var cancelled: Bool { get }/// 是否执行public var executing: Bool { get }/// 是否执行完成public var finished: Bool { get }/// 是否并发的public var concurrent: Bool { get }/// 是否异步操作执行其任务@available(iOS 7.0, *)public var asynchronous: Bool { get }/// 任务能否执行public var ready: Bool { get }/// 任务名@available(iOS 8.0, *)public var name: String?
4 Managing Dependencies
/// 添加子任务public func addDependency(op: NSOperation)/// 去掉子任务public func removeDependency(op: NSOperation)/// 子任务public var dependencies: [NSOperation] { get }
5 Configuring the Execution Priority
/// 任务优先级public var queuePriority: NSOperationQueuePriority/// 线程优先级@available(iOS, introduced=4.0, deprecated=8.0)public var threadPriority: Double/// 资源级别@available(iOS 8.0, *)public var qualityOfService: NSQualityOfService
6 Waiting on an Operation Object
/// 阻塞当前线程的执行,直到完成其任务@available(iOS 4.0, *)public func waitUntilFinished()
Appendix
Sample Code
Swift
Related Documentation
NSOperation Class Reference
Concurrency Programming Guide
Revision History
Copyright
CSDN:http://blog.csdn.net/y550918116j
GitHub:https://github.com/927337973/Blog
0 0
- NSOperation
- NsOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- NSOperation
- 安装SVN Access Manager 0.5.5.1(一)
- nginx向client发送数据包
- 欢迎使用CSDN-markdown编辑器
- MyEclipse快捷键大全( 再排版)
- 经典排序算法之插入排序
- NSOperation
- MFC中BUTTON点击没有反应的解决方法
- Java面向对象(上)
- Android异步任务之AsyncTask源码解析
- NSBlockOperation
- 使用广播接收者获取短信及拦截电话
- 2016跨境电商五大物流模式
- NSOperationQueue
- SSLOJ1531 斐波拉契数列IV