Array of Bool require NSNumber.self in NSKeyedArchiver decoding list of types

I decode an object with NSKeyedArchiver (SecureCoding):

typealias BoolArray = Array<Array<Bool>>
        let val = decoder.decodeObject(of: NSArray.self, forKey: someKey) as? BoolArray

I get the following log:

*** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSNumber' (0x204cdbeb8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSArray' (0x204cd5598) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.

I changed by adding NSNumber.self in the list :

let val = decoder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: someKey) as? BoolArray

No more warning in log.

Is there a reason for this ?

Like the message said, NSKeyedUnarchiver will require a complete list of all possible types for better security in the future.

Accepted Answer

Thanks for the reply.

But the question is: why NSNumber for Bool ?

Likely because Bool is cast to NSNumberfor coding/decoding: https://stackoverflow.com/questions/45610119/swift-casts-bool-to-nsnumber-using-as-operator

Because NSArray can contain only objects, and NSNumber is the class that has been used to box bools, integers, floats, and double since a long time ago.

Array of Bool require NSNumber.self in NSKeyedArchiver decoding list of types
 
 
Q