Cannot get indexOfObject to work
Cannot get indexOfObject to work
- Subject: Cannot get indexOfObject to work
- From: Bartlomiej Cichosz <email@hidden>
- Date: Fri, 19 Mar 2004 14:16:41 -0500
I have a custom class (let's call it CL) derived from NSObject, which
implements isEqual: - currently, for debugging purposes it is defined
as:
- (BOOL)isEqual:(id)anObject {
NSLog(@"isEqual called");
return YES;
}
I also have an NSMutableArray containing number of CL objects. I am
trying to use indexOfObject to locate particular object, but I get
NSNotFound regardless of what I am searching for. My code looks as
follows:
if([[a objectAtIndex:6] isEqual:@"caption"]) {
NSLog(@"Yes, they are the same");
}
i=[a indexOfObject:@"caption"];
if(i==NSNotFound) {
NSLog(@"Not found");
}
Variable a is the NSMutableArray I mentioned. The output I get is:
2004-03-19 13:57:29.435 App[8533] isEqual called
2004-03-19 13:57:29.435 App[8533] Yes, they are the same
2004-03-19 13:57:29.435 App[8533] Not found
It appears that isEqual is never called by indexOfObject, which seems
to be contrary to documentation:
indexOfObject:
- (unsigned)indexOfObject:(id)anObject
Searches the receiver for anObject and returns the lowest index whose
corresponding array value is equal to anObject. Objects are considered
equal if isEqual: returns YES. If none of the objects in the receiver
is equal to anObject, indexOfObject: returns NSNotFound.
See Also: containsObject:, indexOfObjectIdenticalTo:, isEqual:
(NSObject protocol)
Is there a bug in implementation of indexOfObject, or am I
understanding the documentation incorrectly? Of course, I can always
implement search method myself, but it would be nice to know if I am
doing something wrong :-)
Thanks for any help,
Bart
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.