I'm on macOS Monterey (12.0.1), not iOS, objective-c, XCode 13
I'm receiving this log message after building my app for arm64:
[general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1dcb1c848) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(
"'NSDictionary' (0x1dcaee5d0) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
Any idea what's causing this and how to get rid of it?
Edit: it seems to happen with every app compiled on arm64 starting with macOS Monterey. So it might be a generic apple bug
Thanks to @OI Sen it've had a closer look to the NSUnarchiver. First of all NSKeyedUnarchiver should be allocated and initialized like this:
NSError* err;
NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:someData error:&err];
In my specific case I use NSSecure coding. Therefore you have to specify classes on decoding objects. In my case it looked like this
NSDictionary* someDict = [unarchiver decodeObjectOfClass:[NSDictionary class] forKey:NSKeyedArchiveRootObjectKey];
But the NSDictionary contained additional strings. That was the cause of the log message. By adding NSString to the decoded class list the error is gone.
NSDictionary* someDict = [unarchiver decodeObjectOfClasses:[[NSSet alloc] initWithArray:@[[NSDictionary class],[NSString class]]] forKey:NSKeyedArchiveRootObjectKey];
Another related situation is if you're using NSCoder.
This code generated the warning:
self.expression = [aDecoder decodeObjectForKey: kExpression];
Warning eliminated with:
self.expression = [aDecoder decodeObjectOfClass:[NSString class] forKey:kExpression];
Note use of decodeObjectOfClass:[NSString class] instead of decodeObjectForKey.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With