Re: Hiding superclass methods
Re: Hiding superclass methods
- Subject: Re: Hiding superclass methods
- From: email@hidden
- Date: Thu, 09 May 2002 15:00:54 -0700
Brock Brandenberg wrote:
|Is there a way in Obj-C to hide a superclass method so that compiler
|checking would catch/flag any access to that method?
No.
|I have an NSView subclass that is instantiated in code at runtime that
|has a custom initWithFrame:data: method that, in turn, calls the
|initWithFrame: method. I'd like to prevent my accidental use of the
|standard initWithFrame method, if possible
|
|It is acceptable practice to do this, or should I explicitly call an
|additional initializer after my [[obj alloc] initWithFrame:] calls?
If you want your view to work when loaded from a nib file, you're pretty much forced to have *no* initializer (not even initWithFrame:), and to call a separate setData: method to supply the data. Views loaded from nib files never have initializers called, not even initWithFrame:, so any code you might put there would be executed only if you created the view explicitly in your application. (Initialization of views loaded from nib files has to be done in awakeFromNib.)
If you don't intend your view to ever be loaded from a nib file, then I'd have initWithFrame:data: be the designated initializer (which is what you seem to want), then define an initWithFrame: method that simply writes a message to the log indicating it was called when it shouldn't be. (The "stub" initWithFrame: should release the view and return nil, to prevent the calling code from using a half-constructed object.)
Glen Fisher
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.