On Aug 18, 2008, at 1:17 PM, Carmen Cerino Jr. wrote:

Does the id type have enough information for the respondsToSelector method to work. I have a class with an ivar of type id, and when I invoke the respondsToSelector method it fails when it should succeed. I am assuming it should work fine, because if I skip checking with the respondsToSelector method and just make the call, it executes the method. Can someone please tell me what I am doing wrong?

It should work just fine.  This example...

NSArray* theArray = [NSArray array];
id theId = theArray;
id<NSCopying>* theCopyingId = (id<NSCopying>*) theArray;

if ([theArray respondsToSelector:@selector(isEqualToArray:)]) {
    NSLog(@"theArray responds to isEqualToArray:");
} else {
    NSLog(@"theArray DOES NOT respond to isEqualToArray:");
}

if ([theId respondsToSelector:@selector(isEqualToArray:)]) {
    NSLog(@"theId responds to isEqualToArray:");
} else {
    NSLog(@"theId DOES NOT respond to isEqualToArray:");
}

if ([(id) theCopyingId respondsToSelector:@selector(isEqualToArray:)]) {
    NSLog(@"theCopyingId responds to isEqualToArray:");
} else {
    NSLog(@"theCopyingId DOES NOT respond to isEqualToArray:");
}


...displays this output:

theArray responds to isEqualToArray:
theId responds to isEqualToArray:
theCopyingId responds to isEqualToArray:


Note that special casting done to remove warnings. However, without the casting, output was the same.

___________________________________________________________
Ricky A. Sharp         mailto:[EMAIL PROTECTED]
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

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