views:

44

answers:

1

From the Core Data docs:

Inheritance If you have two subclasses of NSManagedObject where the parent class implements a dynamic property and its subclass (the grandchild of NSManagedObject) overrides the methods for the property, those overrides cannot call super.

@interface Parent : NSManagedObject
@property(nonatomic, retain) NSString* parentString;
@end

@implementation Parent
@dynamic parentString;
@end

@interface Child : Parent
@end

@implementation Child
- (NSString *)parentString
{
    // this throws a "selector not found" exception
    return parentString.foo;
}
@end

very, very funny, because: I see nobody calling super. Or are they? Wait... parentString.foo results in ... a crash ??? it's a string. How can that thing have a .foo suffixed to it? Just another documentation bug?

+1  A: 

I think the example is garbled.

I pretty sure the inheritance issue is caused because @dynamic methods are created by the runtime. The complier does not attempt to create a symbol for them. If the parent class isn't instantiated, I don't think the methods even exist at all. Therefore, its really impossible for a subclass instance to have a live selector/symbol to call.

It's a tradeoff necessary for automatic runtime code generation.

TechZen