• 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: Replacing a method via categorys
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacing a method via categorys


  • Subject: Re: Replacing a method via categorys
  • From: Ofri Wolfus <email@hidden>
  • Date: Tue, 28 Jun 2005 11:24:58 +0300

You may want to read this - http://cocoadev.com/index.pl?MethodSwizzling
It explains exactly what you want.

- Ofri

On 28/06/2005, at 00:48, Theodore H. Smith wrote:


I'm trying to replace a method in NSCell, via categories.

First off, let me say I know this is usually a very bad thing to do. Mostly if done wrong, I can introduce bugs into perfectly good code. And also if Apple ever change NSCell, my code might break in the future.

Anyhow, just for experiments sake and assuming I'm responsible for the dangers, I have this question.

If I want to replace a method in a category, how can I get that replacement method to call the original method?


@implementation NSCell (NoHilite)
- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView: (NSView *)controlView {
if (controlView != IgnoredHilite) {
[super highlight:flag withFrame:cellFrame inView:controlView];
}
}


@end

Here I get a compile time error that [super highlight:flag withFrame:cellFrame inView:controlView]; is bad. I'm not sure if it is possible even to call the original method.

Also, the method doesn't even get called (I set breakpoints), and my cells get hilited normally.

Any clues anyone?

--
http://elfdata.com/plugin/ Industrial strength string processing, made easy.


"All things are logical. Putting free-will in the slot for premises in
a logical system, makes all of life both understandable, and free."

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Replacing a method via categorys
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >Replacing a method via categorys (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: dyld: Library not loaded
  • Next by Date: Re: Automator and Webkit
  • Previous by thread: Re: Replacing a method via categorys
  • Next by thread: Re: Replacing a method via categorys
  • Index(es):
    • Date
    • Thread