Since unarchiveObjectWithData() does not exclude throw its exception, there is currently no way to catch it in Swift (starting with a write). The new NSKeyedUnarchiver decodeTopLevelObject() method has NSKeyedUnarchiver added to the iOS 9 SDK, which throws now contains an error. You can catch this with the do , try , catch control flow.
do { let result = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(NSData(...)) } catch { print(error) }
source share