• 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: How do I give a set of methods to some objects but not others?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I give a set of methods to some objects but not others?


  • Subject: Re: How do I give a set of methods to some objects but not others?
  • From: Dustin Voss <email@hidden>
  • Date: Fri, 24 Nov 2006 12:41:03 -0800

On 24 Nov 2006, at 11:59 AM, Alan Smith wrote:

Protocols:
They would work except I would then have to implement it over and over
again and each implementation would be the same. I want to find a way
to only implement the methods once and then use that one
implmentations.

A cheesy way to do this is: make global functions that implement the functionality, and then have each protocol implemented to simply call those globals.


A less cheesy way to do this is: make the formal protocol to mark which classes adhere to it, but actually *implement* it as an informal protocol on NSObject or whatever. The informal protocol implementation can check to see if self adheres to the formal protocol and throw an exception if not.

A strange & hacky was to do this is: use the Objective-C runtime functions, specifically, class_addMethods and sel_registerName, to add the one-and-only implementations of the desired methods to the relevant classes.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How do I give a set of methods to some objects but not others? (From: "Alan Smith" <email@hidden>)
 >Re: How do I give a set of methods to some objects but not others? (From: Daniel Jalkut <email@hidden>)
 >Re: Re: How do I give a set of methods to some objects but not others? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: "undo:" action vs. NSWindow
  • Next by Date: Re: NSString, path and "/" char
  • Previous by thread: Re: Re: How do I give a set of methods to some objects but not others?
  • Next by thread: Re: How do I give a set of methods to some objects but not others?
  • Index(es):
    • Date
    • Thread