Objective-C-Runtime Bug When Naming a Superclass “Message”

前端 未结 1 730
一整个雨季
一整个雨季 2021-01-20 02:32

I have the following class hierachy:

@interface Message : NSObject {}
@end

@implementation Message
- (void) dealloc
{
    // I won\'t be called
    [super d         


        
相关标签:
1条回答
  • 2021-01-20 03:17

    Objectve-C lacks the concept of namespaces. The problem is well known and usually worked-around by using prefix-namespaces (like NSObject or MKMapView). You could name your message class JrMessage to avoid the clash with the (undocumented) class named Message.

    The compiler could only warn you if it knew about the other class. In the case of private, undocumented classes, this often is not the case. The best way to handle this is to avoid clashes by using the prefix on every class. This also helps against future clashes, when Apple adds classes to a new release of the OS (which the compiler obviously couldn't warn about).

    Edit:

    Further investigation shows that the competing class origins from a private Framework named "MIME.framework", at least on the iPhone Simulator:

    NSLog(@"Message class: %@", [[NSBundle bundleForClass:NSClassFromString(@"Message")] bundlePath]);
    
    ... Message class: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/System/Library/PrivateFrameworks/MIME.framework
    

    You might want to add this information in your bug report.

    0 讨论(0)
提交回复
热议问题