• 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: The Unadopted Protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Unadopted Protocol


  • Subject: Re: The Unadopted Protocol
  • From: Greg Parker <email@hidden>
  • Date: Wed, 2 Jun 2010 11:11:50 -0700

On Jun 2, 2010, at 8:57 AM, Matt Neuburg wrote:
> So this appears to be a technique for implementing a highly informal
> protocol. (The technique is: define a protocol, don't bother adopting it
> anywhere, but send messages defined in that protocol to an id.)

Yep. When the compiler looks for a method declaration matching a message sent to `id`, it looks at every declaration encountered up to that point in the file.

That's comparable to the traditional way to create informal protocols: declare a category on NSObject, don't bother implementing it anywhere, and send messages declared in that category to other objects.

In general we discourage both of these now. The problem is that somebody somewhere is likely to declare a method with the same name but different parameter types. In these cases - message to `id` and category on NSObject - the compiler has no way to know which declaration to use. If it guesses wrong, your code may be doomed.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

  • Follow-Ups:
    • Re: The Unadopted Protocol
      • From: Matt Neuburg <email@hidden>
    • Re: The Unadopted Protocol
      • From: Matt Neuburg <email@hidden>
References: 
 >The Unadopted Protocol (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: Delayed -dealloc occurs on worker thread if object is "working". How?
  • Next by Date: Re: Delayed -dealloc occurs on worker thread if object is "working". How?
  • Previous by thread: Re: The Unadopted Protocol
  • Next by thread: Re: The Unadopted Protocol
  • Index(es):
    • Date
    • Thread