Pro*_*ber 2 performance multithreading nsoperation nsoperationqueue ios
我的应用程序必须在iOS 3.2上运行,而诸如-addOperationWithBlock之类的方法只能在> 4.0中运行.
但是NSOperationQueue从iOS 2.0开始就可用,所以我想尝试一下"老方法".有没有人知道一个方便的教程,它显示了如何在没有块的情况下使用NSOperationQueue的基础知识?
使用Invocation操作非常简单.这些操作允许您使用某个对象参数(可选)将消息发送到特定对象.
因此,假设您要调用此方法:
- (void)doSomething {
NSLog (@"Did it!");
}
Run Code Online (Sandbox Code Playgroud)
你可以做这样的事情来实现它:
// Get or create some queue
NSOperationQueue *someQueue = [NSOperationQueue mainQueue];
// create an invocation operation
NSInvocationOperation *invocationOp = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(doSomething)
object:nil];
[someQueue addOperation:invocationOp]; // Add the operation to the queue
[invocationOp release];
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
2619 次 |
| 最近记录: |