简体   繁体   English

那么,这个超级叫哪里呢?

[英]So where is this calling super?

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. 继承如果您有两个NSManagedObject子类,其中父类实现了动态属性,并且其子类(NSManagedObject的孙子类)覆盖了该属性的方法,则这些覆盖不能调用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 ??? 等待... parentString.foo导致...崩溃? it's a string. 这是一个字符串。 How can that thing have a .foo suffixed to it? 那东西怎么有后缀.foo? Just another documentation bug? 只是另一个文档错误?

I think the example is garbled. 我认为这个例子是乱码。

I pretty sure the inheritance issue is caused because @dynamic methods are created by the runtime. 我很确定是由于运行时创建了@dynamic方法而导致了继承问题。 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. 这是自动生成运行时代码所必需的权衡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM