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

1

6

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.

 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?

Tachycardia answered 15/4, 2012 at 11:5 Comment(0)
N
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.

Nepenthe answered 15/4, 2012 at 11:10 Comment(4)
It cannot be done ,because the object should not be referenced by any other function without get update from web.Tachycardia
Please paste some more code so I can help. All I can say in general is that there is no logic in "return value" when we are talking about asynchronous behavior.Nepenthe
In my application when i flip a page the layout of the next page is set according to the data driven from web.It's dynamic and cannot predict the number of subviews.That's why i was thinking to return the layout in threaded function.Tachycardia
OK, the direction of thought sounds good. Why not call a method that does whatever magic needs to be done on the view when the data finishes loading? (This means at the end of the method being called by the thread)Nepenthe

© 2022 - 2024 — McMap. All rights reserved.