NSCopying / NSMutableCopying Protocols


Read the NSCopying Protocol and NSMutableCopying Protocol documentation.

NSObject defines basic default behaviour for copying instances of classes. This works great for simple classes like strings et al.

If you define a compound class, like “Appliance” and want specific copying behaviour it is your responsibility to implement these protocols in a manner that makes it so.


I think you misunderstood the docs. This code, for example, fails to execute correctly:

[code]#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
@autoreleasepool {
id obj = [[NSObject alloc] init];
id obj2 = [obj copy];
NSLog(@“Hello, World! %@”, obj2);
return 0;

The error thrown is [NSObject copyWithZone:]: unrecognized selector sent to instance 0x7fa6a3c14050