UIBezierPath -copyWithZone: breaks subclass NSCopying implementation

Originator:jtbandes
Number:rdar://13047823 Date Originated:18-Jan-2013
Status:Closed Resolved:iOS 7 beta 6
Product:iPhone SDK Product Version:6.0
Classification:Serious Bug Reproducible:Always
 
Summary:
UIBezierPath conforms to NSCopying, but its -copyWithZone: always returns an instance of UIBezierPath. This means that subclasses cannot easily implement copyWithZone: because [super copyWithZone:] returns an object of the wrong class.

Steps to Reproduce:

- Use the following subclass:

	@interface MyPath : UIBezierPath
	@end
	@implementation MyPath
	- (id)copyWithZone:(NSZone *)zone
	{
		MyPath *obj = [super copyWithZone:zone];
		// obj is of the wrong class; can't set custom properties!
		return obj;
	}
	@end

- Test with the following code:

	MyPath *path = [[MyPath alloc] init];
	NSLog(@"Path: %@", [path class]);
	NSLog(@"Copy: %@", [[path copy] class]);

Expected Results:
[path class] == [[path copy] class] == [MyPath class]

Actual Results:
[path class] == [MyPath class], but [[path copy] class] == [UIBezierPath class]

Notes:
According to the NSCopying documentation:
"If a subclass inherits NSCopying from its superclass and declares additional instance variables, the subclass has to override copyWithZone: to properly handle its own instance variables, invoking the superclass’s implementation first."

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!