nayem nayem - 2 years ago 128
iOS Question

How to initialize an NSArray with NSString?

I'm using a property of an NSArray. Then I'm trying to initialize or setting values for the NSArray. When I tried shorthand assignment, I'm getting the output. I tried to do that in Objective-C style. But I'm not able to get the result. What should be the right way for the long initialization style??
Here is the code snippet:

@property NSArray * moods;

NSLog(@"Hello %@",[self moods]);

This is working. But when I tried with this:

[[self moods]initWithObjects:@"Happy",@"Sad", nil];
NSLog(@"Hello %@",[self moods]);

this isn't doing the same way.
Suggest me something please.

Answer Source

just some alternative approaches without dots... ;)

[self setMoods:@[@"Happy", @"Sad"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download