I have a custom object which gets passed back to the main app from XPC.
I whitelist it like so:
NSSet *expectedClass = [NSSet setWithObjects:[NSArray class],
[MyCustomClass class],
nil];
[interface setClasses:expectedClass forSelector:@selector(myMethodNameHere:withCompletion:)
argumentIndex:0
ofReply:YES];
Now my custom class conforms to NSSecureCoding. It does have an array property of another custom class.
@property (nonatomic,readonly) NSArray *arraypropertyOfOtherClass;
Which is decoded in -initWithCoder: using:
-decodeArrayOfObjectsOfClasses:forKey:
Now on macOS Tahoe this is all walking fine. But I just tested on macOS Monterey and I get the following error:
Exception: decodeObjectForKey: too many nested collections when explicitly decoding a single collection.
How should I handle this for earlier versions of macOS?
So using -decodeObjectOfClasses:forKey: with the NSArray class and the custom class (like I mentioned in the above post) works on macOS 12.7.
// in the -initWithCoder
NSSet *classesSet = [NSSet setWithObjects:[NSArray class],[MyCustomClass class],nil];
_arraypropertyOfOtherClass = [aDecoder decodeObjectOfClasses:classesSet forKey:@"myKey"];
Not sure when -decodeArrayOfObjectsOfClasses:forKey: started working but beware of this if you are deploying back to 12.7, you can't use -decodeArrayOfObjectsOfClasses:forkey: with XPC.