• 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: Jean-Daniel Dupas <email@hidden>
  • Date: Thu, 28 Aug 2008 14:32:55 +0200

Le 28 août 08 à 13:24, Christian Giordano a écrit :

Protocols seems definitely the way to go and seems to work, I'm only
getting some warnings. Basically what I did, I pass the instance
implementing the protocol with this syntax:

- (void) addListener:(id <MyProtocol> *) listener

and I get "invalid receiver type 'id <MyProtocol>*'

Funny enough after I get another warning. I basically want to add the
listener to a NSMutableArray with this syntax:

[listeners addObject:listener]

and I get "passing arguments 1 of 'addObject:' from incompatible pointer type.

I am new to Objective-C so I thought in my ignorance, maybe id
<MyProtocol> defines already a pointer and removing the "*" doesn't
gives those errors but where I was checking for the conformity with:
`
Removing the "*" is what you need, but that's not <MyProtocol> that is a pointer, but "id".




if ( ! [listener conformsToProtocol:@protocol(MyProtocol)]  ) {

I get "'-conformsToProtocol:' not found in protocol(s)"

Any idea?


When you use the id<protocol> syntaxt, the compiler assume your object only implements the method declared in your protocol.
If you want to use some other function, you have to use an object type that declare thoses functions, for example in your case, NSObject.


- (void) addListener:(NSObject <MyProtocol> *) listener

there is a nice article that explains it better here:

http://unixjunkie.blogspot.com/2008/03/id-vs-nsobject-vs-id.html


_______________________________________________

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: Phil <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>)

  • Prev by Date: Re: CFBundleIconFile: heiß or hot?
  • Next by Date: Re: Design Question: Bindings & Custom Views
  • Previous by thread: Re: Creating Interface
  • Next by thread: Re: Creating Interface
  • Index(es):
    • Date
    • Thread