Tag: nscopying

复制和mutableCopy如何适用于NSArray和NSMutableArray?

在NSArray或NSMutableArray上使用copy和mutableCopy什么区别? 这是我的理解; 这是对的吗? // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@"abc", @"def", nil]; // No copy, increments retain count, result is immutable NSArray *myArray_imuCopy = [myArray_imu copy]; // Copys object, result is mutable NSArray *myArray_imuMuta = [myArray_imu mutableCopy]; // Both must be released later // ** NSMutableArray ** NSMutableArray *myArray_mut = [NSMutableArray arrayWithObjects:@"A", @"B", […]

实现NSCopying

我已经阅读了NSCopying文档,但是我仍然不确定如何实现所需的东西。 我的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 Vendor类有一个名为Car的对象数组。 我的Car对象: @interface Car : NSObject { BOOL isAvailable; NSString *transmissionType; NSMutableArray *vehicleCharges; NSMutableArray *fees; } @property (nonatomic, assign) BOOL isAvailable; […]