从这里抛出的错误没有处理.... bug

时间:2016-01-15 21:15:52

标签: ios xcode swift nsdictionary xcode7

有人可以解释为什么我会根据其他代码的位置收到此错误吗?

enter image description here

为什么编译正常:

func serializeJSONData(jsonData: NSData) -> NSDictionary {
    do {
        let searchResultsJSON: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) as! NSDictionary
        return searchResultsJSON
    } catch let error as NSError {
        print("json error: \(error.localizedDescription)")
        let returnDictionary = [:]
        return returnDictionary
    }
}


func parseForms(formsArray: NSArray) -> NSArray {

    var retVal = [SearchFormObject]()
    for form in formsArray as! NSDictionary { }

    return retVal
}

当我像这样切换方法时:

func parseForms(formsArray: NSArray) -> NSArray {

    var retVal = [SearchFormObject]()
    for form in formsArray as! NSDictionary { }

    return retVal
}

func serializeJSONData(jsonData: NSData) -> NSDictionary {
    do {
        let searchResultsJSON: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) as! NSDictionary
        return searchResultsJSON
    } catch let error as NSError {
        print("json error: \(error.localizedDescription)")
        let returnDictionary = [:]
        return returnDictionary
    }
}

我在

上收到错误
let searchResultsJSON: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) as! NSDictionary

这是IDE还是我的代码中有实际错误?

0 个答案:

没有答案