Cocoa - Return information from NSOperation

后端 未结 3 1181
青春惊慌失措
青春惊慌失措 2021-02-06 10:08

I have an IPhone app that uses webservices to get data from a server. I\'m putting each call to the webservice in a NSOperation subclass so that it can be threaded. My questio

3条回答
  •  伪装坚强ぢ
    2021-02-06 10:21

    The doc says it's better to make the operation member variable when you want get the result from operation. But I do not think the solution will adapt you.

    I think notification is good and There is another way to get the result is make a completion block for your own operation.See here: Return data from NSOperation? I tried it's work well.

    I tried another way before.set the operation completion block,and make a weak reference to operation and make the result an property of operation. so you can get the operation result when you finished.

    But completion is not reliable,when you cancel the operation the completion excuted too. so choose the best for you.

提交回复
热议问题