gpt4 book ai didi

Swift 3 调用结果 (_ :parameters:completionHandler:)' is unused warning and Braced block of statements is an unused closure error

转载 作者:行者123 更新时间:2023-11-28 11:01:05 26 4
gpt4 key购买 nike

我有工作 Swift.2.3 项目,但是当我构建并将其转换为 Swift3 时,它给我:

Result of call to (_:parameters:completionHandler:)' is unused warning. Warning.

下面是我清晰的工作代码,我怎样才能用真正的方式转换它们?

InmyClass;

     private func getMoviesDirectorsFromJSON(jsonData: NSData) throws -> [Director] {
var directors = [Director]()
do {
if let jsonObject = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments) as? [String: AnyObject], jsonArray = jsonObject["Actors"] as? [[String: AnyObject]] {
for i 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 {
do {
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()

}
}
}

使用时;

 @discardableResult

给我错误;

Braced block of statements is an unused closure

最佳答案

您可以使用 @discardableResult 注释它警告您的方法。

例如:

@discardableResult
func foobar() -> Bool {
return true
}

关于Swift 3 调用结果 (_ :parameters:completionHandler:)' is unused warning and Braced block of statements is an unused closure error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com