Unable to add object to NSMutableArray

@interface SimataDetailViewController () @property Simata *simata; @property (nonatomic, copy) NSMutableArray *simataList; @end @implementation SimataDetailViewController @synthesize simataDataController=_simataDataController; @synthesize category=_category; @synthesize simata=_simata; @synthesize simataList=_simataList; #pragma mark - Managing the detail item - (void) getSimataForCategory: (NSString *) inputCategory { unsigned count = [self.simataDataController.masterList2 count]; while (count--) { if ([[[self.simataDataController objectSimataInListAtIndex:count] categoryCode] isEqual:inputCategory]){ self.simata= [self.simataDataController objectSimataInListAtIndex:count]; [self.simataList addObject:self.simata]; } } NSLog(@"count, %u", [self.simataList count]); } 

Hi, this is my first post, so please be patient.

I am trying to add a self.simata object to the self.simata array, but the array remains with null objects. The self.simata object self.simata not nil , and I am not getting any errors.

What am I doing wrong?

+4
source share
2 answers

Are you sure you created an instance of the array before using it?

 self.simataList =[NSMutableArray array]; 

It could be your self.simata, zero ...

EDIT

You can create an array instance in the default init method:

 -(id)init { self = [super init]; if(self) { //do your object initialization here self.simataList =[NSMutableArray array]; } return self; } 
+5
source

Most likely self.simataList is zero. Try NSLogging self.simataList and not its score.

+1
source

Source: https://habr.com/ru/post/1400885/


All Articles