如何从通过NSthread调用的函数中获取返回值?

时间:2022-03-02 20:39:23

I wrote a function which returns an object. But it is a function which takes data from web.So NSthread is used to call the function.

我写了一个返回对象的函数。但它是一个从web获取数据的函数。NSthread被用来调用函数。

 NSThread* pageThread = [[NSThread alloc]initWithTarget:self selector:@selector(threadFunction) object:nil];

How to get a return value from a function which is called through NSthread?

如何从通过NSthread调用的函数中获取返回值?

1 个解决方案

#1


1  

The "return value" shouldn't be returned by the method, but it should update a class iVar and notify whoever was waiting for the object that it is now ready (by notify I don't necessarily mean NSNotificationCenter). Good luck.

“返回值”不应该由方法返回,但是它应该更新一个类iVar,并通知任何等待该对象的对象,它现在已经准备好了(通过通知我并不一定意味着NSNotificationCenter)。祝你好运。

#1


1  

The "return value" shouldn't be returned by the method, but it should update a class iVar and notify whoever was waiting for the object that it is now ready (by notify I don't necessarily mean NSNotificationCenter). Good luck.

“返回值”不应该由方法返回,但是它应该更新一个类iVar,并通知任何等待该对象的对象,它现在已经准备好了(通过通知我并不一定意味着NSNotificationCenter)。祝你好运。