App Crashing: Mutating method sent to immutable object

天大地大妈咪最大 提交于 2019-12-02 07:31:34

The object you're retrieving from the responseObject dictionary is most likely not an NSMutableArray, but an (immutable) NSArray. You have to create a mutable copy to be able to change it:

//...
if (!_myArray) {
    _myArray = [[responseObject objectForKey:@"data"] mutableCopy];
}
//...
Catfish_Man

It sounds like AFNetworking generates immutable objects. You should call -mutableCopy instead of just assigning the result of -objectForKey: directly.

Also are you really intending to have a bunch of nested arrays? It seems like it would make more sense if you added the contents of the response array, rather than the array itself.

You need to make the copy of your array. After that you have to modify that array using, [NSMutableArray arrayWithArray: ]

Your array is must be mutable array

Use NSMutablearray instead NSArray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!