NSKeyedUnarchiver - try/catch needed?

前端 未结 2 1557
既然无缘
既然无缘 2021-02-05 06:37

As I understand, the use of @try/@catch blocks is discouraged, because exceptions should only be thrown at unrecoverable, catastrophic errors (refer to

2条回答
  •  庸人自扰
    2021-02-05 07:05

    There was a new method added in iOS 9 to NSKeyedUnarchiver that now returns an error:

    Swift:

    public class func unarchiveTopLevelObjectWithData(data: NSData) throws -> AnyObject?
    

    Objective-C:

    + (nullable id)unarchiveTopLevelObjectWithData:(NSData *)data error:(NSError **)error;
    

    However, this is not backwards compatible with previous versions of iOS, so you will need to check for framework availability.

提交回复
热议问题