Tag: nscopying

Implementing NSCopying in Subclass of Subclass

I have a small class hierarchy that I’m having trouble implementing copyWithZone: for. I’ve read the NSCopying documentation, and I can’t find the correct answer. Take two classes: Shape and Square. Square is defined as: @interface Square : Shape No surprise there. Each class has one property, Shape has a “sides” int, and Square has […]

Why zone is always nil while implementing NSCopying?

It may be simple question, but why implementing NSCopying protocol in my class, I get zone == nil – (id)copyWithZone:(NSZone *)zone { if (zone == nil) NSLog(@”why this is allways nil”); (…) } This is called using this method for copy array with objects. [[NSArray alloc] initWithArray:myArray copyItems:YES]];

Implementing NSCopying

I’ve read the NSCopying docs but I am still very unsure about how to implement what is required. My class Vendor: @interface Vendor : NSObject { NSString *vendorID; NSMutableArray *availableCars; BOOL atAirport; } @property (nonatomic, copy) NSString *vendorID; @property (nonatomic, retain) NSMutableArray *availableCars; @property (nonatomic, assign) BOOL atAirport; – (id)initFromVehVendorAvailsDictionary:(NSDictionary *)vehVendorAvails; @end The Vendor class […]