通过苹果文档
主要-
For non-concurrent operations, you typically override only one method:
main
开始-
When you add an operation to an operation queue, the queue ignores the value of the asynchronous property and always calls the start method from a separate thread. Therefore, if you always run operations by adding them to an operation queue, there is no reason to make them asynchronous.
如果我必须执行 Alamofire 的代码,它已经使用了操作队列并且是异步的。我应该在哪里编写代码(Main 或 Start)来调用 Alamofire 请求?
最佳答案
也许我没有捕获你答案的要点,但是,如果你需要将 Alamofire 包装在自定义操作中,则必须创建一个异步 NSOperation
。
您可以在this Github repo中找到一个很好的例子。 .
关键点是:
- 覆盖返回
true
的异步
属性 - 覆盖
start
方法 - 控制
isExecuting
和isFinished
属性以更改操作的状态
关于cocoa - 使用 NSOperation main() 和 start() 方法中的哪一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36679635/