Hi guys,
I was following along with a Lynda.com tutorial to help myself get back into Objective-C and I am stuck on one line of code:
(FYI moods is an NSArray defined as a property in my .m file)
I can not for the life of me translate this into something that is not dot notation. No single way of converting this has worked for me and there are far too many to post what I've tried and I'm getting frustrated.
I don't understand how a dot notation works just fine but when I try and do something like:
[[self moods] blah blah blah I get nothing but errors and warnings. I'm sure something is wrong syntax wise but I can't figure it out and I haven't found one example online or in my Steve Kochan or Big Nerd Ranch books that address how to do this.
Can anyone translate that one line of code into a non-dot syntax line please?
EDIT: One such example is if I try and do this:
I get an "Expression result unused" error.
EDIT: Solved!
It's:
I know some people like dot syntax (and yes its convenient) but I hate it for this very reason. It obscures the message being called. The self is what threw me off.
I was following along with a Lynda.com tutorial to help myself get back into Objective-C and I am stuck on one line of code:
(FYI moods is an NSArray defined as a property in my .m file)
Code:
[B]self.moods [/B]= @[@"Happy", @"Sad", @"Maudlin", @"Ecstatic", @"Overjoyed", @"Optimistic", @"Bewildered",
@"Cynical", @"Giddy", @"Indifferent", @"Relaxed"];
I can not for the life of me translate this into something that is not dot notation. No single way of converting this has worked for me and there are far too many to post what I've tried and I'm getting frustrated.
I don't understand how a dot notation works just fine but when I try and do something like:
[[self moods] blah blah blah I get nothing but errors and warnings. I'm sure something is wrong syntax wise but I can't figure it out and I haven't found one example online or in my Steve Kochan or Big Nerd Ranch books that address how to do this.
Can anyone translate that one line of code into a non-dot syntax line please?
EDIT: One such example is if I try and do this:
Code:
[[self moods] initWithObjects:@"Happy", nil];
EDIT: Solved!
It's:
Code:
[self setMoods:@[@"Happy", @"Sad", @"Maudlin", @"Ecstatic", @"Overjoyed", @"Optimistic", @"Bewildered",
@"Cynical", @"Giddy", @"Indifferent", @"Relaxed"]];
I know some people like dot syntax (and yes its convenient) but I hate it for this very reason. It obscures the message being called. The self is what threw me off.
Last edited: