知道为什么我不能获得我确定存在于数组中的对象的索引吗?相反,我得到了 nil..
(lldb) po newItem
<ReceiptItem: 0x16a428b0>
(lldb) po self.items
<__NSArrayM 0x169bf0e0>(
<ReceiptItem: 0x16a428b0>
)
(lldb) po [self.items indexOfObject:newItem]
<nil>
谢谢
最佳答案
-indexOfObject:
返回类型为 NSUInteger
的整数,而不是对象引用。因此,您不应使用 po
(打印对象)调试器命令,而应使用 p
。
它返回0
,而不是nil
,这意味着它在数组的第一个位置找到了对象。如果找不到对象,-indexOfObject:
将返回 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.
关于ios - NSArray indexOfObject 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30555966/