调用方法有错误:预期参数(变量) - >()

时间:2017-06-29 21:24:16

标签: swift function methods completionhandler

我正在尝试使用完成处理程序调用方法,但我似乎无法在没有此错误的情况下调用它。我对它的要求感到困惑。

这是我可以调用的方法:

 func fillFromFile(completionBlock: @escaping ([Asset_Content]) -> ()) {
    let url = "URLSTRING"

    LoadJSONFile(from: url) { (result) in
        // The code inside this block would be called when LoadJSONFile is completed. this could happen very quickly, or could take a long time

        //.map is an easier way to transform/iterate over an array
        var newContentArray = [Asset_Content]()
        for json in result{
            let category = json["BIGCATEGORY"] as? String
            let diagnosis = json["DIAGNOSIS"] as? String
            let perspective = json["PERSPECTIVE"] as? String
            let name = json["NAME"] as? String
            let title = json["Title"] as? String
            let UnparsedTags = json["TAGS"] as? String
            let filename = json["FILENAME"] as? String

            let tagArray = UnparsedTags?.characters.split(separator: ",")
            for tag in tagArray!{
                if(!self.ListOfTags.contains(String(tag))){
                    self.ListOfTags.append(String(tag))
                }
            }

            let asset = Asset_Content(category!, diagnosis!, perspective!, name!, title!, filename!)
            // This is a return to the map closure. We are still in the LoadJSONFile completion block
            newContentArray.append(asset)

        }
        print("return count ", newContentArray.count)
        // This is the point at which the passed completion block is called. 
        completionBlock(newContentArray)
    }
}

0 个答案:

没有答案