swift3 - Swift 3 Result of call to (_:parameters:completionHandler:)' is unused warning and Braced block of statements is an unused closure error -
i have working swift.2.3
project when build , convert swift3
gives me:
result of call (_:parameters:completionhandler:)' unused warning. warning.
my clear working codes under below, how can convert them true way?
inmyclass;
private func getmoviesdirectorsfromjson(jsondata: nsdata) throws -> [director] { var directors = [director]() { if let jsonobject = try nsjsonserialization.jsonobjectwithdata(jsondata, options: .allowfragments) as? [string: anyobject], jsonarray = jsonobject["actors"] as? [[string: anyobject]] { in jsonarray { var properties = [string: anyobject]() properties[directorjsonkeys.id] = i[directorjsonkeys.id] properties[directorjsonkeys.firstname] = i[directorjsonkeys.firstname] properties[directorjsonkeys.lastname] = i[directorjsonkeys.lastname] properties[directorjsonkeys.name] = i[directorjsonkeys.name] properties[directorjsonkeys.imageurl] = i[directorjsonkeys.imageurl] let director = director(properties: properties) directors.append(director) } } } catch { throw myapperrors.parsingerror } return directors } public func directorshmovieswithmethod(method: string, parameters: string, completionhandler: (director: [director]?, error: errortype?) -> void) -> nsurlsessiontask! { let session = nsurlsession.sharedsession() guard let url = nsurl(string: parameters) else { completionhandler(director: nil, error: myapperrors.invalidurlerror) return nil } let request = nsurlrequest(url: url) let task = session.datataskwithrequest(request) { data, response, error in if error != nil { completionhandler(director: nil, error: myapperrors.moviesearcherror) } else { { let director = try self.getmoviesdirectorsfromjson(data!) completionhandler(director: director, error: nil) } catch { completionhandler(director: nil, error: error) } } } task.resume() return task } public func downloadimageatlocation(location: string, completionhandler: (imagedata: nsdata?, error: errortype?) -> void) -> nsurlsessiontask! { let configuration = nsurlsessionconfiguration.defaultsessionconfiguration() let session = nsurlsession(configuration: configuration) guard let url = nsurl(string: location) else { completionhandler(imagedata: nil, error: myapperrors.invalidurlerror) return nil } let request = nsmutableurlrequest(url: url) let task = session.datataskwithrequest(request) {data, response, error in if error != nil { completionhandler(imagedata: nil, error: myapperrors.imagedownloaderror) } else { completionhandler(imagedata: data, error: nil) } } task.resume() return task }
inmyview
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0)) { myapp.sharedinstance().directorshmovieswithmethod("", parameters: myurl+"&dataformat=json") {directors, error in if error != nil { dispatch_async(dispatch_get_main_queue()) { self.showalert() } } else { dispatch_async(dispatch_get_main_queue()) { self.directors = directors! self.collectionview2.reloaddata() } } }
when using ;
@discardableresult
gives me error;
braced block of statements unused closure
you can annotate method warning @discardableresult
.
for example:
@discardableresult func foobar() -> bool { return true }
Comments
Post a Comment