淘先锋技术网

首页 1 2 3 4 5 6 7
if  ( commentArray == nil ) {
                
commentArray  = [[ NSMutableArray   alloc init ];
            }
            
            
commentArray  = ( NSMutableArray *)[responseObject  objectForKey : @"comment ];

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** First throw call stack:

一个不可变的数组调用了可变数组中的方法(添加/删除等)

    if ( commentArray == nil ) {
                commentArray = [[ NSMutableArray alloc ] init ];
            }
           
           
NSArray *array = [responseObject objectForKey : @" comment " ];
           
           
for ( int i= 0 ; i<array. count ; i++) {
               
               
NSDictionary *dic = [array objectAtIndex :i];
                [
commentArray addObject :dic];
               
            }
           
            [
commentArray addObject : @"nihao" ];