Swift 调用方法时出错:应为参数(变量)->;()
我试图用一个完成处理程序调用一个方法,但是如果没有这个错误,我似乎无法调用它。我对它的要求感到困惑 以下是我可以调用的方法:Swift 调用方法时出错:应为参数(变量)->;(),swift,function,methods,completionhandler,Swift,Function,Methods,Completionhandler,我试图用一个完成处理程序调用一个方法,但是如果没有这个错误,我似乎无法调用它。我对它的要求感到困惑 以下是我可以调用的方法: func fillFromFile(completionBlock: @escaping ([Asset_Content]) -> ()) { let url = "URLSTRING" LoadJSONFile(from: url) { (result) in // The code inside this block woul
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)
}
}
您会遇到什么错误?当我尝试仅使用方法调用它时,我会得到“调用中缺少'CompletionBlock'参数”检查您传递的参数,以使URL函数正常工作。可能它需要一些整数值,而您正在传递字符串,这会导致缺少参数