How to use completionHandler Closure with return in Swift?

后端 未结 4 1334
轮回少年
轮回少年 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:10

    The completion handler can't return anything because the closure you have to supply has to be of return type Void and not AnyObject!.

    func dataTaskWithRequest(_ request: NSURLRequest!,
       completionHandler completionHandler: ((NSData!,
                                  NSURLResponse!,
                                  NSError!) -> Void)!) -> NSURLSessionDataTask!
    

提交回复
热议问题