Sahar Max Sahar Max - 21 days ago 4x
Objective-C Question

How to add new array element from another method in Objective-c?

I have some array( @private NSArray employees []; ) and method , which take string parameter( name of employees) and put this parameter in array. How I can do this with Objective-c?


You could do the following,

Create a property,

@property (nonatomic) NSMutableArray *array;

Initialise the array in your init method or somewhere else appropriate,

self.array = [[NSMutableArray alloc] init];

Your method could look something like this,

- (void)addEmployeeName:(NSString *)employeeName {
   [self.array addObject:employeeName];