Search code examples
objective-cnsmutablearraylvalue

Objective C - Lvalue required as left operand of assignment


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?


Solution

  • 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.