小编Ven*_*bhu的帖子

call可以抛出,但是没有标记为"try"并且没有处理错误

override func viewDidLoad(){super.viewDidLoad()

    //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)

        }
    }

}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

try-catch swift3 ios10

-2
推荐指数
1
解决办法
8497
查看次数

标签 统计

ios10 ×1

swift3 ×1

try-catch ×1