small medium large xlarge

05 Jul 2009, 17:00
Rob (1 post)

I’m am confused about when it is possible and not possible to use dot notation.

For example, I modified the movie player code slightly (after browsing apple documentation) to use an mutable array of stars for the movie rating, so it can return 1 to 5 starts in this case (not exactly a good implementation, but you get the idea…)

In initWithTitle: I have added:

rating = [NSMutableArray arrayWithObjects:@"*", @"**", @"***", @"****", @"*****", nil];

I created get/set also:

- (void)setRating:(NSMutableArray*)theRatingArray
	NSLog(@"made it here");
	rating = theRatingArray;

- (NSString*)rating:(int)theRating
	return [rating objectAtIndex:(theRating - 1)];

This works and runs just fine…. until I change code to self.rating:

self.rating = [NSMutableArray arrayWithObjects:@"*", @"**", @"***", @"****", @"*****", nil];

then i get….

Error: request for member 'rating' in something not a structure or union

… but if i add an (assign) property + synthesize as well as my own get/set it seems to work just fine.

I want to know why I cant use self.rating with my own get/set on its own?

05 Jul 2009, 22:45
Bill Dudney (917 posts)

Hi Rob,

self.rating means ‘invoke the get method’, self.rating = foo means ‘invoke the set method’. If you don’t have a property declared you can’t use ‘self.rating’ for get or set.

Hope this helps.

You must be logged in to comment