Question: I am having some trouble trying to share a `NSMutableArray` of Strings to another class. I have a `tableView` that is populated with `Strings` that I would like to add to a `NSMutableArray`. Then use that SAME `NSMutableArray` in another `ViewController`

I have created a class with the subclass of `NSMutableArray`

**.h**

```
#import <Foundation/Foundation.h>

@interface HYServicesMArray : NSMutableArray

@property (nonatomic, weak)NSMutableArray * arrServicesUserChoice;

@end

```

**.m**

```
#import "HYServicesMArray.h"

@implementation HYServicesMArray

@dynamic arrServicesUserChoice;

@end

```

I am trying to add elements to this `NSMutableArray` from a `tableView didSelectRowAtIndexPath:`

**.m**

```
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    NSLog(@"You have selected: %@",cell.textLabel.text);

    // add cell.textLabel.text to arrServicesUserChoice 
    // Tried the code below but causes my app to crash  
      arrServicesUserChoice = [[NSMutableArray alloc]init];
      [arrServicesUserChoice addObject:cell.textLabel.text];
}

```

[![enter image description here](https://i.stack.imgur.com/jgups.png)](https://i.stack.imgur.com/jgups.png)

How ever I am unable to add elements to the `arrServicesUserChoice`. I am stuck please help! Thank you in advance!

Answer: 
YOu declared a mutable array, and the code you used to add returns an array, but it dont add anyting. you have to add the objects like:

```
     [arrAvaialbleServicesList addObject:cell.textlabel.text];

```

After this, your mutable array will have the added data

or you can declare another array, and do it your way"

```
 NSArray *test=[arrAvaialbleServicesList arrayByAddingObject:cell.textLabel.text];

```

after this, the new array will have the array with added data.
What you try to create is a kind of public static var correct? i think the better way to do that is creating an Class that can handle your MutableArray object. Doing her as a singleton class is a good way to guarantee that you will not create another instance of your object and lost your MutableArray. Here is a sample:

HYServicesMArray.h

```
#import <Foundation/Foundation.h>

@interface HYServicesMArray : NSObject

@property (nonatomic, strong) NSMutableArray *arrServicesUserChoice;

+ (HYServicesMArray *) instance;

@end

```

HYServicesMArray.m

```
#import "HYServicesMArray.h"

@implementation HYServicesMArray

+ (HYServicesMArray *)instance
{
    static HYServicesMArray *_ServicesMArray = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _ServicesMArray = [[self alloc] init];
    });
    return _ServicesMArray;
}

-(id)init {
    self.arrServicesUserChoice = [[NSMutableArray alloc] init];
    return self;
}

@end

```

And the application on your didSelectRowAtIndexPath method:

```
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    NSLog(@"You have selected: %@",cell.textLabel.text);

    [[HYServicesMArray instance].arrServicesUserChoice addObject:cell.textLabel.text];
}

```