Swift3 call可以抛出,但它没有标记为";试一试;并且错误不会被处理
重写func viewDidLoad(){ super.viewDidLoad() 数据(contentsOf:url!as url)可能引发异常,您需要尝试调用。Swift3 call可以抛出,但它没有标记为";试一试;并且错误不会被处理,swift3,try-catch,ios10,Swift3,Try Catch,Ios10,重写func viewDidLoad(){ super.viewDidLoad() 数据(contentsOf:url!as url)可能引发异常,您需要尝试调用。 通过使用let optData=try?…如果引发异常,您将拥有有效的数据对象或为零谢谢,您节省了我的时间。guard let jsonresponse=try?JSON(数据:数据)else{failure(“error”)return} //get the values from sql/Json let ur
通过使用let optData=try?…如果引发异常,您将拥有有效的数据对象或为零谢谢,您节省了我的时间。guard let jsonresponse=try?JSON(数据:数据)else{failure(“error”)return}
//get the values from sql/Json
let url = URL(string: "https://example.com/dropdownmenu/phpGet.php")
let data = Data(contentsOf: url! as URL)
var tmpValues = try! JSONSerialization.jsonObject(with: data as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
tmpValues = tmpValues.reversed() as NSArray
reloadInputViews()
for candidate in tmpValues {
if let cdict = candidate as? NSDictionary {
//fullName is the column name in sql/json
let names = cdict["fullName"]
self.values.append(names! as AnyObject)
}
}
}
let optData = try? Data(contentsOf: url! as URL)
guard let data = optData else {
return
}