Wait for code to finish execution

前端 未结 2 1988
孤街浪徒
孤街浪徒 2020-12-17 01:39

I would like to know the easiest way to wait for code to finish execution within an objective c project because I am calling a webservice and retrieving the results and inst

2条回答
  •  半阙折子戏
    2020-12-17 02:09

    You could use one of many of the Cocoa design patterns (Delegate, Notification, etc).

    For instance you would trigger the method and wait until you receive a response back.

    It looks like you are using an asynchronous request and for this case, you would need to wait until one of the delegate methods get notified that the request has finished (with error or success).

    BTW, what does your request look like? Could you share some code to explain how you do the request and when and what you want to do?

    Edited after the code was inserted:

    You set self as the delegate of the request, and so you should be able to handle the responses.

    Have a look at the NSURLConnection Class Reference. You will need to trigger your parser when the request finishes on these methos, for example:

    – connection:didReceiveResponse:
    – connection:didReceiveData:
    – connection:didFailWithError:
    

    Cheers,

    vfn

提交回复
热议问题