views:

77

answers:

3

Hi,

I get the error (Lvalue required as left operand of assignment) for this code:

[[addAlertViewController alertsArray] = [NSMutableArray arrayWithObjects:nil] retain];

How can I fix it?

A: 

Try this :

addAlertViewController.alertsArray = [[NSMutableArray arrayWithObjects:nil] retain];

However, if you have declared alertsArray property to retain, then you don't need to send the retain message.

taskinoor
Thanks, it fixed that but now I get other error:request for member 'alertsArray' in something not a structure or union
Guy Dor
You haven't declared the property. Before asking in this site, you should first learn the basics of C and iPhone programming. These are all basic things which can be solved by googling and reading some texts.
taskinoor
Actually, more likely he has declared the property but hasn't imported the header file into the file he is getting the error in.
JeremyP
true. that also might be the case.
taskinoor
A: 

The appropriate Code is as follows:

[addAlertViewController setAlertsArray:[NSMutableArray arrayWithObjects:nil]];

Be careful that you have declared in your @interface of addAlertViewController's Class:

@property (nonatomic, retain) NSMutableArray *alertsArray;

And in your implementation file

@synthesize alertsArray;

And.. I'll agree with @taskinoor, RTFM.

Stephen Furlani
+1  A: 

Knowing what an lvalue and rvalue will help when deciphering compiler warnings. A lvalue is something that will be assigned and a rvalue is something that can do the assigning. More info on wikipedia

An rvalue can also be a lvalue, like in the case of a = b = c (where c is an rvalue to lvalue b, but then b is a rvalue to the lvalue a).

anytime you see "lvalue required" then look on the left of the = operator, there is an error there.

Brent Priddy