我不明白髮生了什麼事情。正如你所看到的,我有一個107個對象的數組。當我試圖從它複製只有10個對象到另一個數組時,我得到這個錯誤。 (如果像3,8我輸入數字它會正常工作)索引超出範圍與對象索引
int count = [myJson count];
NSLog(@"count: %d",count);
resultsArray = [myJson objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(60, 70)]];
...
[53269:11303] count: 107
[53269:11303] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectsAtIndexes:]: index 129 in index set beyond bounds [0 .. 106]'
答案是問題之內。你的數組只有106個對象,你試圖訪問第129個對象。你的'NSRangeMake'會導致這個問題。檢查https://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/miscellaneous/foundation_functions/reference/reference.html#//apple_ref/c/func/NSMakeRange –
-1對於濫用NSRangeMake。文件清楚地解釋了它是如何工作的。 – borrrden
我確定這兩個值都是索引...感謝您的幫助和-1。我需要那個! – Segev