NSArray indexOfObject 返回 nil

NSArray indexOfObject returning nil

知道为什么我无法获得我确定存在于数组中的对象的索引吗?相反,我没有..

(lldb) po newItem
<ReceiptItem: 0x16a428b0>

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

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

谢谢

-indexOfObject: returns 是 NSUInteger 类型的整数,不是对象引用。因此,您不应使用 po(打印对象)调试器命令,而应使用 p

是returns 0,不是nil,什么意思,它在数组的第一个位置找到了对象。如果找不到对象,-indexOfObject: 会 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.

尝试这样做

(lldb) p (NSUInteger)[self.items indexOfObject:newItems];