• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hiding superclass methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Hiding superclass methods
      • From: Ondra Cada <email@hidden>
References: 
 >Hiding superclass methods (From: Brock Brandenberg <email@hidden>)

  • Prev by Date: Hiding superclass methods
  • Next by Date: Re: Hiding superclass methods
  • Previous by thread: Hiding superclass methods
  • Next by thread: Re: Hiding superclass methods
  • Index(es):
    • Date
    • Thread