• 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: Creating Interface
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating Interface


  • Subject: Re: Creating Interface
  • From: Roland King <email@hidden>
  • Date: Thu, 28 Aug 2008 22:32:08 +0800


On Aug 28, 2008, at 10:15 PM, Sherm Pendley wrote:

On Thu, Aug 28, 2008 at 9:56 AM, Roland King <email@hidden> wrote:
I tried that before, making my protocol inherit from the NSObject Protocol and it sort of worked, but not quite.


Protocols aren't inherited. You can inherit an implementation of the NSObject protocol, by writing a subclass of the NSObject class, but that's a very different animal.

let me use Apple's terminology instead of my own sloppy one, you can 'incorporate' other protocols into your own, so my first shot was


@protocol Foo <NSObject>

but that fails addObserver:... if you use (id<Foo>) as addObserver:.. isn't part of NSObject so what I wanted was

@protocol Foo <NSObject, NSKeyValueObserving>

but NSKeyValueObserving  isn't really defined so you can't do that



I don't quite understand why protocols like NSKeyValueObserving aren't formalized and in a .h file somewhere so you could just use them in the same way you can the NSObject protocol. They're documented, why not just write the .h file. There's probably a very good reason for it which has totally escaped me.

Conforming to a protocol is an all-or-nothing affair - you have to implement *all* of the protocol's methods. The informal protocols I'm aware of tend to have one or more optional methods.


You can have @optional Protocol methods (is that new, that may be new, I'm really not sure). Of course if the protocols ended up all optional then indeed that would rather defeat the purpose of the whole thing. That's a very good point though. I'm still more used to interfaces in other languages which really are all-or-nothing.


sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net


_______________________________________________

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: Creating Interface
      • From: Chris Hanson <email@hidden>
References: 
 >Creating Interface (From: "Christian Giordano" <email@hidden>)
 >Re: Creating Interface (From: Matthias Schonder <email@hidden>)
 >Re: Creating Interface (From: "Christian Giordano" <email@hidden>)
 >Re: Creating Interface (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Creating Interface (From: Phil <email@hidden>)
 >Re: Creating Interface (From: Roland King <email@hidden>)
 >Re: Creating Interface (From: "Sherm Pendley" <email@hidden>)

  • Prev by Date: Re: Creating Interface
  • Next by Date: Re: mark added object in NSArrayController as "dirty"?
  • Previous by thread: Re: Creating Interface
  • Next by thread: Re: Creating Interface
  • Index(es):
    • Date
    • Thread