udacity / ios-nd-networking

Resources for Udacity's iOS Networking with Swift course.
MIT License
172 stars 88 forks source link

Silence warnings for unused return type in taskForGETRequest. #7

Open OwenLaRosa opened 5 years ago

OwenLaRosa commented 5 years ago

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.

ssvedin commented 5 years ago

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