Swift 3调用结果(_:参数:completionHandler:)'未使用的警告和Braced的语句块是未使用的关闭错误

时间:2016-11-10 11:34:00

标签: swift swift3

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

  

调用结果(_:参数:completionHandler :)'是未使用的警告。   警告。

我在下面明确的工作代码,如何以真实的方式转换它们?

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

给我错误;

  

声明的语句块是未使用的闭包

1 个答案:

答案 0 :(得分:3)

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

例如:

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