0

I am creating a class Ticket. In that ticket I want a mutable array of NSStrings i.e. in ticket.h

@interface Ticket : NSObject
@property NSString *ticketName;
@property NSMutableArray *games;

However Objective C doesn't allow me to do this. What am I supposed to do to have an array inside an object?

I then want to store that array using encodeWithCoder in the implementation of the object

2
  • 1
    Did you missing @property (nonatomic,strong) ? Commented Feb 3, 2015 at 7:51
  • 1
    I think you have a syntax problem Commented Feb 3, 2015 at 7:53

1 Answer 1

3

like i said you might have a syntax problem, there is no reason why Objective-c won't allow you to add an NSMutableArray into your custom objects, try this:

    @interface MyObject : NSObject

    @property (nonatomic, strong) NSMutableArray *myMutableArray;

    //
    // .. other properties
    //

    @end

and in the implementation

@implementation MyObject

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self.myMutableArray addObject:@"myString1"];
  [self.myMutableArray addObject:@"myString2"];
  [self.myMutableArray addObject:@"myString3"];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Wow! I found other web articles that said it couldn't be done and had been avoiding it for ages. Thanks for clearing this up.
Glad to help my friend!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.