简体   繁体   中英

Objective C - Objects not being added to NSMutableArray

I have a custom class which has a property, which is of type NSMutableArray. When I try to add an object, it does not give me an error, but does not add that object either. Following is that class.

@interface ClassA : NSObject

@property (atomic,strong) NSMutableArray *prop1;

@end

This is another class, of whose object I'm trying to assign to Class

Then, in another class, I am trying to add an object to that property.

NSString *test = @"";
ClassA *classA = [[ClassA alloc] init];
classA.prop1 = [[NSMutableArray alloc] init];
[classA.prop1 addObject:test];

But, when I am debugging, classA.prop1 has 0 elements . It worked earlier, without an issue. But this behaviour started off suddenly. I cannot remember changing anything in the project. This behaviour is seen across the entire project. I am at a loss. Could anyone please help me?

Declare your NSMutableArray array as nonatomic

@interface ClassA : NSObject

@property (nonatomic,strong) NSMutableArray *prop1;

@end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM