简体   繁体   中英

Possible compiler bug in Xcode?

Here is the situation: I have created a custom view class with UITextView as its member. I make textView as a first responder after some event occurs.

@inteface MyCustomView : UIView{
   UITextView* textView;
}

- (void) doSomething;

@end

During program execution I send [doSomething] message to MyCustomView's instance.

[myCustomViewInstance doSomething];

What happens is very interesting, the program crashes by complaining that UITextView:doSomething is unrecognized selector.

Why is the program calling doSomething on UITextView (its member variable) instead of MyCustomView's instance.

What could be possibly wrong here ? (of course this is a canonical version of what I am doing but I don't understand in any logical error scenario this could be true unless something is messed up at compiler level)

What do you think I should investigate further ?

First, Objective-C doesn't have "member" variables, it has instance variables. Minor thing; but terminology does matter.

Secondly, the crash is happening because myCustomViewInstance is pointing to an instance of UITextView and not your subclass. This may be because you made such an assignment inadvertently or it may be because you have an over-release issue and it so happens that said variable ends up pointing to the wrong object by coincidence.

Finally, while there are certainly compiler bugs, it is exceedingly unlikely that such straightforward code would unveil a heretofore unknown compiler bug. The compiler you are using is the very same one that is used to compile the umpteen millions of lines of code of the OS; such a simple bug would very likely means no apps would work or, quite likely, the device wouldn't even boot.

That assumes that said line of code is actually what is crashing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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