ios-nd-networking icon indicating copy to clipboard operation
ios-nd-networking copied to clipboard

Silence warnings for unused return type in taskForGETRequest.

Open OwenLaRosa opened this issue 6 years ago • 1 comments

After making the change to cancel the search task, you probably noticed some annoying warnings like this.

Result of call to 'taskForGETRequest(url:responseType:completion:)' is unused

Ever since we added the return type, Xcode now shows warnings every time we call it without assigning something to the URLSessionDataTask it returns. But for the most part, we don't actually need to access the returned task.

A quick fix, is to add the @discardableResult annotation before the declaration of the taskForGETRequest function (this is an annotation just like adding @escaping before a closure). Doing so will silence the warnings.

OwenLaRosa avatar Nov 09 '18 22:11 OwenLaRosa

@discardableResult class func taskForGETRequest<ResponseType: Decodable>(url: URL, responseType: ResponseType.Type, completion: @escaping (ResponseType?, Error?) -> Void) -> URLSessionDataTask {

ssvedin avatar Mar 22 '19 03:03 ssvedin