简体   繁体   中英

Xcode 7.0 Swift Update Problems

I'm trying to update my project to work with Xcode 7.0 and after updating my Swift projects I'm getting an error that I don't understand on this line.

let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary

The error is

"Call can throw, but it is not marked with 'try' and the error is not handled"

I'm also getting these two errors in my project files...

"linker command failed with exit code 1 (use -v to see invocation)"

and

"error: cannot parse the debug map for "/Users/MattFiler/Library/Developer/Xcode/DerivedData/ePlanner-cqwzlxqgpwaloubjgnzdlomjkfea/Build/Intermediates/SwiftMigration/ePlanner/Products/Debug-iphonesimulator/ePlannerTests.xctest/ePlannerTests": No such file or directory"

You need to try and catch if it throws an error.

do {
    let jsonData:NSDictionary = try NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary
    //...
}
catch {
}

Try this code:

do {
    let jsonData = try NSJSONSerialization.JSONObjectWithData(urlData!, options: .MutableContainers ) as! NSDictionary
    // Use jsonData here
} catch {
    print("Well something happened: \(error)")
}

You'll need the try keyword as NSJSONSerialization.JSONObjectWithData now throws an error if something failed since Swift 2. Throwing functions need to be marked with try or try! .

Also you'll need the do { ... } catch to catch any errors that may occur. This will catch the error and handle it.

You might want to read up on the changes in Swift 2 to understand why this happened. Also the WWDC videos will be very helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM