gpt4 book ai didi

ios - NSIncationOperation - 不在不同线程上调用方法吗?

转载 作者:行者123 更新时间:2023-11-29 04:54:39 25 4
gpt4 key购买 nike

所以我有一个服务 clint 类,它有一个名为 fetch 的方法。我使用 NSIncationOperation 调用此方法。当我检查线程时,它似乎正在主线程上调用方法。使用 NSIncationOperation 异步运行的全部意义不就是这样吗?

调用方法

ServiceClient *client = [[ServiceClient alloc] init];
NSInvocationOperation *invocatopnOperation = [[NSInvocationOperation alloc] initWithTarget:client selector:@selector(fetch) object:nil];
[invocatopnOperation start];

服务客户端中的方法

- (void)fetch
{
if ([[NSThread currentThread] isEqual:[NSThread mainThread]])
{
NSLog(@"NOOOOOO");
}
............
}

最佳答案

来自 NSInitationOperation 类引用:

The NSInvocationOperation class is a concrete subclass of NSOperation that manages the execution of a single encapsulated task specified as an invocation. You can use this class to initiate an operation that consists of invoking a selector on a specified object. This class implements a non-concurrent operation.

这意味着为了异步执行操作,您需要将其添加到操作队列中。

关于ios - NSIncationOperation - 不在不同线程上调用方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232062/

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