操作系统x和目标C的新功能。我的程序崩溃了几个用户报告我无法在我的机器上重现它。
Feb 22, 2014, 9:06:44 AM: An uncaught exception was raised
Feb 22, 2014, 9:06:44 AM: *** -[NSArray getObjects:range:]: range {3392, 16} extends beyond bounds for empty array
Feb 22, 2014, 9:06:44 AM: (
0 CoreFoundation 0x00007fff8f05541c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff94c12e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ef9bc9f -[NSArray getObjects:range:] + 271
3 CoreFoundation 0x00007fff8ef9da63 -[NSArray countByEnumeratingWithState:objects:count:] + 163
4 MYAppMac 0x00000001000037b9 +[ITunesProvider getITunesMediaFiles:] + 5209
行崩溃行指向此for循环
// Get tracks from iTunesUserPlaylist
SBElementArray *fileTracks = [list fileTracks];
for(iTunesFileTrack* track in fileTracks)
{
// my code here. I do not modify filetracks anywhere in the loop
}
for循环遍历数组中的项目,但在某些时候它会崩溃尝试进一步访问项目。我根本不修改fileTracks数组。有什么想法正在发生什么?
答案 0 :(得分:1)
刚遇到同样的问题。您可以根据用户使用iTunes执行的操作,对正在进行更改的实时阵列进行迭代。您可以尝试使用-get
获取数组并迭代生成的固定NSArray
,如下所示:
NSArray* fileTracks = [[list fileTracks] get];
for (iTunesFileTrack* track in fileTracks)
{
// Your code
}