我有下面的类层次结构:目的-C运行时错误当命名超类“消息”
@interface Message : NSObject {}
@end
@implementation Message
- (void) dealloc
{
// I won't be called
[super dealloc];
}
@end
@interface FooMessage : Message {}
@end
@implementation FooMessage
- (void) dealloc
{
// should call Message - dealloc
[super dealloc];
}
@end
和以下单元测试:
- (void) test
{
FooMessage* msg = [[FooMessage alloc] init];
[msg release];
}
测试将总是失败,并EXC_BAD_INSTRUCTION 。 FooMessage
称它为dealloc
中的超类析构函数,但是电话永远不会到达那里。相反,Objective-C运行解析调用到不同的位置:
如果Message
基类被重命名为别的东西,如不发生错误AbstractMessage
。看起来还有另一个类Message
,其定义不公开。
这是一个错误?这里发生了什么?我是否违反了任何命名限制(即使我认为编译器应该警告我)?
这是XCode 3.1。编译为iPhone OS 3.0。
无前缀的类是系统框架中的一个错误。您的控制台上可能会有关于碰撞的消息。通过http:// bug reporter.apple.com/ – bbum 2010-05-17 14:43:25
@bbum提交bug:您是否知道Apple在文档中提供关于类名的承诺? – 2010-05-17 15:48:12
这是...倒退。但是,谢谢你的信息。 – 2010-05-17 16:09:16