NSArray indexOfObject returning nil

Yossi

Any idea why can't I get the index of an object that I'm sure is exist in the array? Instead, I'm getting nil..

(lldb) po newItem
<ReceiptItem: 0x16a428b0>

(lldb) po self.items
<__NSArrayM 0x169bf0e0>(
<ReceiptItem: 0x16a428b0>
)

(lldb) po [self.items indexOfObject:newItem]
<nil>

Thanks

Amin Negm-Awad

-indexOfObject: returns an integer of type NSUInteger, not an object reference. Therefore you should not use po (print object) debugger command, but p.

It returns 0, not nil, what means that it found the object at the first position of the array. If it would not find the object, -indexOfObject: would return NSNotFound.

The lowest index whose corresponding array value is equal to anObject. If none of the objects in the array is equal to anObject, returns NSNotFound.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related