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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to