我有這樣的代碼:錯誤。如果命令,對象爲零
if (self.leadObject != nil) {
[result addObject:self.leadObject];
}
有時應用密切與此錯誤:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
執行過,如果命令,並嘗試添加對象裏面self.leadObject
result
數組雖然此對象是nil
。 有人可以解釋這一點嗎?
更新:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: (0x2ca8af87 0x3a1e9c77 0x2c9a6f29 0x1777ff 0x177a6f 0x177b7f 0x1779df 0x17446d 0xa1cdd 0xa7933 0x46cad3 0x46cabf 0x47051b 0x2ca50e61 0x2ca4f581 0x2c99cdb1 0x2c99cbc3 0x33d28051 0x2ff68a31 0xadb45 0x3a785aaf) libc++abi.dylib: terminating with uncaught exception of type NSException
'self.leadObject'的實現看起來像什麼? –
你確定這次墜機是由這部分造成的嗎?我建議在'[add addObject:self.leadObject]'之前添加一個日誌狀態語句',在其中打印'self.leadObject'的值,以確保... – nburk
請從崩潰中粘貼堆棧跟蹤的副本登錄到您的問題。 –