[MyClass initWithCoder:]: unrecognized selector sent to instance - On iOS16

 am using the [NSKeyedUnarchiver unarchiveObjectWithData:result] methode for unarchiving NSData in my objective c bases app.

`NSMutableArray *array = (NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:result];

This is working pretty fine upto iOS15. But since iOS16 I am getting a crash that [MyClass initWithCoder:]: unrecognized selector sent to instance 0x281069760. I can see that unarchiveObjectWithData methods is deprecated. So as suggested in xcode, now I have tried

`NSError *err; @try { NSMutableArray *array = (NSMutableArray *)[NSKeyedUnarchiver unarchivedObjectOfClass:[NSMutableArray class] fromData:result error:&err]; } @catch (NSException *exception) { NSLog(@"Exception %@", exception.reason); }

Now I am getting nil value for my array and the err is err = 0x0000000281ff1020 domain: nil - code: 4864 There were no issues before I updated my iPad to iPadOS 16. Any help is appreciated.

The correct pattern for calling initWithCoder as an instance method and not a class method, which doesn't exist provided you didn't create a class version of the method, is [[MyClass alloc] initWithCoder: aCoder]. And what the error above is telling you is the variable or property result points to nothing. Always perform a NULL check on the result before passing it to unarchiveObjectWithData:.

[MyClass initWithCoder:]: unrecognized selector sent to instance - On iOS16
 
 
Q