How to use completionHandler Closure with return in Swift?

后端 未结 4 1337
轮回少年
轮回少年 2020-12-02 09:52

I am trying to us a RESTful API that returns some json data. I want to encapsulate the code that creates the HTTP Request and sets the headers in its own method so I can cal

4条回答
  •  长情又很酷
    2020-12-02 10:18

    as you see here, the dataTaskWithRequest:completionHandler: has a completion handler with no expected return value.

    completion handler's interface

    that means the NSURLSession instance do not expect any value from you to proceed after calling this method; with other words: you completion closure (or block, if you like) ends the procedure here.

    there is not clear why you'd like sending back anything to the caller via the completion handler.

提交回复
热议问题