I just ran into a similar problem and it was weird and extremely time consuming. I wanted to test my class for the correctness of NSSecureCoded with Specta / Expecta . Thus, I implemented everything as needed, defining the class when decoding. At the end of my tests, I received a strange exception:
value for key 'key' was of unexpected class 'MyClass'. Allowed classes are '{( MyClass )}'.
The test looked something like this:
MyClass *myClassInstance = ... NSMutableData *data = [NSMutableData data]; NSKeyedArchiver *secureEncoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [secureEncoder setRequiresSecureCoding:YES];
While normal NSCoding testing (requireSecureCoding = NO) was successful, NSSecureCoding tests continued to fail. After a wide range of tests, I found a solution for this, just one line:
[secureDecoder setClass:[MyClass class] forClassName:NSStringFromClass([MyClass class])];
After that, all my tests were successful, the objects were created as expected.
I'm not sure why this happened, I assume that the class will not display as Ben H , and it uses something like NSClassFromString(@"MyClass") . The above code worked fine in AppDelegate. MyClass was one of the developers I'm developing.
MANIAK_dobrii
source share