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?

Muhammed Basil
  • 1,834
  • 1
  • 21
  • 39

1 Answers1

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.

Stavash
  • 14,244
  • 5
  • 52
  • 80
  • It cannot be done ,because the object should not be referenced by any other function without get update from web. – Muhammed Basil Apr 15 '12 at 11:18
  • 5
    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. – Stavash Apr 15 '12 at 11:19
  • 1
    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. – Muhammed Basil Apr 15 '12 at 11:27
  • 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) – Stavash Apr 15 '12 at 11:31