在我的應用程序中,我設置了NSArray
,並將所有具有HTML文件擴展名的對象從文檔目錄添加到它。
我使用這個數組來填充UITableView
但是...我不斷得到警告NSArray VS. NSMutableArray問題
'NSArray' may not respond to 'removeObjectAtIndex:'
如果我將其更改爲NSMutableArray
則該警告會消失,但新的警告這裏彈出:
self.files = [[[manager contentsOfDirectoryAtPath:documentsDirectoryPath
error:nil]
pathsMatchingExtensions:[NSArray arrayWithObjects:@"html", nil]] retain];
這一警告是:
Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'
的應用程序工作正常,如編輯表格視圖從來沒有產生任何親儘管存在removeObjectAtIndex:
問題。
長的語句分解爲單獨的線,它是一個更容易發現錯誤。你會立即看到'[[manager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil]'返回了一個'NSArray'而不是一個NSMutableArray。 OPr在該線上找到指出錯誤的錯誤。在一條線上組合操作沒有收益。 – zaph