• 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: Ondra Cada <email@hidden>
  • Date: Fri, 10 May 2002 01:00:45 +0200

On Thursday, May 9, 2002, at 11:36 , 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? 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, but haven't found any relevant information in the Obj-C book.

Can't be done in a clean way. If you insist, you can eg. #define initWithFrame to something ugly, but I don't think it would be sensible.

You should be aware though that compile-time checking would be good for nothing anyway: eg. the plainest expression

[[YourClass alloc] initWithFrame:...]

would *NOT* be catched by compiler, since alloc returns an id!

The only reasonable way is to catch the thing at runtime, and that could be done easily using doesNotRecognizeSelector:.

It is acceptable practice to do this, or should I explicitly call an additional initializer after my [[obj alloc] initWithFrame:] calls?

Very acceptable.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.

References: 
 >Hiding superclass methods (From: Brock Brandenberg <email@hidden>)

  • Prev by Date: Re: about @selector
  • Next by Date: Re: Saving NSColor
  • Previous by thread: Re: Hiding superclass methods
  • Next by thread: Re: Hiding superclass methods
  • Index(es):
    • Date
    • Thread