Reputation: 9342
Consider the following snippet that tries to created an NSKeyedUnarchiver
from an invalid NSData
object.
NSData *data = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
When I run this on an iOS 8.4 simulator, I get an NSInvalidArgumentException
. On an iOS 9.1 simulator, however, the initializer simply returns nil
.
However, according do the official docs, the method should always throw an exception on invalid data.
This method throws an exception if data is not a valid archive.
Why does it only throw an exception on iOS8 but not on iOS9? Is this new behavior in iOS 9 that was simply not documented yet?
Upvotes: 1
Views: 252
Reputation: 637
Yes, confirmed iOS 9 devices ( not sure of simulator ) will throw an exception under certain circumstances. Here is an example exception which I am currently looking into.
NSInvalidArgumentException
Description: *** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x2d, 0xffffffa4, 0xffffffb3, 0x44, 0xffffffbe, 0xffffff89, 0xffffffcb, 0xffffffcf)
Upvotes: 2