gpt4 book ai didi

multithreading - 是否有关于如何在没有 block 的情况下使用 NSOperationQueue 的教程?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:18 25 4
gpt4 key购买 nike

我的应用程序必须在 iOS 3.2 上运行,并且 -addOperationWithBlock 等方法只能在 > 4.0 中使用。

但是 NSOperationQueue 从 iOS 2.0 开始可用,所以我想尝试一下“旧方法”。有谁知道一个方便的教程,它展示了如何在没有 block 的情况下使用 NSOperationQueue 的基础知识?

最佳答案

调用操作非常简单。这些操作允许您使用某些对象参数(可选)向特定对象发送消息。

给定您要调用的方法:

- (void)doSomething {

NSLog (@"Did it!");
}

你可以做这样的事情来实现它:

// 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];

希望对您有所帮助。

关于multithreading - 是否有关于如何在没有 block 的情况下使用 NSOperationQueue 的教程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com