- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 iOS5 中使用 NSInvocationOperation
和 NSOperationQueue
开发。根据关于调用对象的苹果文档:
The NSInvocationOperation class is a concrete subclass of NSOperation... This class implements a non-concurrent operation.
好的,那么我的 NSInvocationOperation
对象是同步执行的吗? (在这里纠正我)Apple 的文档还提到了操作队列对象:
In iOS, operation queues do not use Grand Central Dispatch to execute operations. They create separate threads for non-concurrent operations and launch concurrent operations from the current thread.
我正在使用 NSInvocationObject
,这是一个非并发对象,并将其添加到操作队列中,如下所示:
[operationQueue addOperation:operation];
所以我的问题是:1) 由于操作队列将产生一个单独的线程来执行 NSInvocationObject,正如它在文档中所说的那样,它会异步运行而不是同步运行吗?
[更新 - 回应 Dani 在下方的回答。取自 Apple link .
NSOperation and NSOperationQueue
There are a number of different ways that you can use NSOperation, but the most common is to write a custom subclass and override one method: main. The main method gets called to perform the operation when the NSOperationQueue schedules it to run. NSOperation classes written in this way are known as non-concurrent operations, because the developer is not responsible for spawning threads—multi-threading is all handled by the super class. (Don’t be confused by the terminology: just because an operation is non-concurrent, does not mean it cannot be executed concurrently, it simply means that you don't have to handle the concurrency yourself.)
If you need more control over threading and the run-time environment of your operations, you can make use of concurrent operations. To do this, you subclass NSOperation and override the start method. In the start method, you can spawn threads and setup the environment before calling the main method. You are also required to maintain the state of the NSOperation by setting properties like isExecuting and isFinished. In short, concurrent operations give you a lot more control, but also demand more effort—for most tasks non-concurrent operations suffice.
最佳答案
如果将它添加到操作队列中,它将相对于您的其余代码异步运行,但在操作队列中同步运行。这很像:
With synchronous objects:Creating thread | |\ | \______ | | | Operation A | | | Operation B | | | |With asynchronous objects:Creating thread | |\ | \___________________ | | |\ Operation A | \______ | | | | | Operation B | | | | | | |
关于objective-c - NSInvocationOperation 和 NSOperationQueue 并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454137/
我在操作里面取消一个NSInvocationOperation是不是对的?示例: .h文件: //defined in the interface NSInvocationOperation *op1
我知道类似的问题已被问过几次,但我正在努力了解如何解决这个特定问题。到目前为止,我所做的一切都是在主踏板上进行的。我现在发现我需要执行一个需要一些时间的操作,我想在操作期间向我的显示器添加一个 HUD
- (void)viewDidLoad { NSOperationQueue *operationQueue = [[NSOperationQueue alloc]init];
我已经在我的项目中编写了代码 [NSInvocationOperation alloc] initWithTarget:
我正在尝试使用 NSInvocationOperation 对一些 TWRequest 调用进行排队。它似乎以正确的顺序添加方法调用,但 doSomething: 方法几乎同时被调用,即并发运行,而不
我正在尝试创建 NSInvocationOperation 以便它应该使用参数调用对象的方法 - (void) getImages: (NSRange) bounds { NSOperatio
我有一个 NSInvocationOperation,它会在后台下载和解析一系列 NSXMLDocuments 以响应我的 UI。 我尝试停止调用操作是调用我的 NSOperationQueue 的
Objective-C/iOS 领域的新手。拥有 PHP 和 C++ 经验。 我在使用 NSInvocationOperation 时遇到了一些问题。这是我的情况: 借助一些在线帮助,我有一个类 ge
1) 当我们在 NSoperationQueue 中添加 NSOperation 或 NSInvocationOperation 时发生了什么? 2) NSoperation 和 NSInvocati
我正在将我制作的 Android 应用移植到 iOS。 Android 有一个 Yield() 函数可以将线程从运行中移到线程队列的后面(?)。这很有用,这样该线程就不会占用过多的 CPU 并使其他一
Foundation Framework 中共有三个操作类(NSOperation、NSInvocationOperation 和NSBlockOperation)。 我已经阅读了 concurren
我正在尝试将 NSOperation 对象放入 NSOperationQueue 中。但似乎我误解了如何正确初始化 NSInvocationOperation(一个似乎为我的目的量身定制的子类,因为我
我在 iOS5 中使用 NSInvocationOperation 和 NSOperationQueue 开发。根据关于调用对象的苹果文档: The NSInvocationOperation cla
我有一个相当简单但昂贵的任务需要在后台运行,这是标准的 NSOperation 情况。我还需要确保该操作支持取消并适当停止。鉴于该要求,哪种方法更好:只是将昂贵的方法调用包装在 NSInvocatio
我的代码突然无法在 Xcode 6.1 中编译(我确定它在 Xcode 6 GM 和 beta 版本中工作)。它显示错误消息: 'NSInvocationOperation' is unavailab
我试图让我的 UITableView 在浏览大约 700 张从 Internet 下载、缓存(到内部存储)并显示在表格的每个单元格上的图片时保持平滑。就滚动性能而言,我的代码到目前为止似乎还不错。但是
我是一名优秀的程序员,十分优秀!