NSMutableArray removeAllObjects 崩溃 [英] NSMutableArray removeAllObjects crash
问题描述
Car class
--------------
price
color
崩溃代码是:
NSMutableArray *list = [[NSMutableArray alloc] init];
Car *car = [[Car alloc] init];
car.price = 10;
car.color = 1;
[list addObject:car];
// some code
[list removeAllObjects]; // Crash here
为什么会崩溃,我该如何解决.
why crash, how can i resolve it.
应用退出,没有任何输出
app exit with nothing output
推荐答案
我不知道你的段中的someCode"部分有什么.您首先注释掉该代码并检查应用程序是否崩溃.如果它仍然崩溃,那么只考虑我在下面给出的内容.我的意思是在采取变通方法之前,您要确保您的代码没有任何问题:)
I dont know what you have in the "someCode" section in your segment. You first comment out that code and check if the app crashes. If still it crashes then only consider what I have given below. I mean you make sure there is nothing wrong with your code before going for workarounds :)
试试这个代码,看看它现在是否崩溃.我知道这没有意义,但它也发生在我身上.有一次当数组计数为零时,removeAllObjects 对我来说崩溃了.我怀疑那里的某个地方存在 SDK 错误 :(
just try this code, and see if it crashes now.I know it doesn't make sense, but it happened to me once too. Once when array count was zero removeAllObjects crashed for me. I doubt an SDK bug somewhere there :(
if([list count]){
[list removeAllObjects];
}
这篇关于NSMutableArray removeAllObjects 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!