iPhone - Crash using addObject on a NSMutableArray

前端 未结 5 1528
悲哀的现实
悲哀的现实 2020-12-10 19:42

I have a problem here. Or Maybe I\'m really tired...

I have a class :

@interface THECLASS : UIViewController  {
    NSMuta         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 19:54

    Your property is defined as retain, and you say that param is "a filled array from the caller view". This could be your problem.

    For example, if you do the following:

    NSArray * filledArray = [NSArray arrayWithObjects:..., nil];
    theClassInstance.param = filledArray;
    

    You will have retained a non-mutable array.

    Edit: To debug the setting of param, you could do the following in your .m:

    @dynamic param;
    - (NSMutableArray*)param { return param; }
    - (void)setParam:(NSMutableArray*)newArray {
        NSLog(@"setting new param from class: %@",
              NSStringFromClass([newArray class]));
        [newArray retain];
        [param release];
        param = newArray;
    }
    

提交回复
热议问题