Sahar Max Sahar Max - 1 year ago 97
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?

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download