Swift: Extra argument 'error' in call

前端 未结 3 2165
广开言路
广开言路 2020-11-22 05:49

I\'m currently developing my first iOS app using Swift 2.0 and Xcode Beta 2. It reads an external JSON and generates a list in a table view with the data. However, I\'m gett

3条回答
  •  误落风尘
    2020-11-22 06:32

    This has been changed in Swift 3.0.

     do{
                if let responseObj = try JSONSerialization.jsonObject(with: results, options: .allowFragments) as? NSDictionary{
    
                    if JSONSerialization.isValidJSONObject(responseObj){
                        //Do your stuff here
                    }
                    else{
                        //Handle error
                    }
                }
                else{
                    //Do your stuff here
                }
            }
            catch let error as NSError {
                    print("An error occurred: \(error)") }
    

提交回复
热议问题