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
-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.
Try to do this
(lldb) p (NSUInteger)[self.items indexOfObject:newItems];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With