Objective C - Lvalue required as left operand of assignment
I get the error (L开发者_运维技巧value required as left operand of assignment) for this code:
[[addAlertViewController alertsArray] = [NSMutableArray arrayWithObjects:nil] retain];
How can I fix it?
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.
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.
精彩评论