Reputation: 419
I'm getting a strange error when assigning a value to one of my objects. As best as I can figure out, the compiler thinks I'm assigning to a read only variable. It gives me "lvalue required as left operand of assignment" on the myPlace.publicLocation... line.
I'm sure it's a classic novice mistake - where am I going wrong?
CSPlace *myPlace;
myPlace.publicLocation.coordinate.latitude =
[[separatedData objectAtIndex:0] floatValue];
class:
#import <CoreLocation/CLLocation.h>
@interface CSPlace : NSObject {
CLLocation *publicLocation;
}
@property (copy, nonatomic) CLLocation *publicLocation;
@end
#import "CSPlace.h"
@implementation CSPlace
@synthesize publicLocation;
@end
Upvotes: 2
Views: 7895
Reputation: 6869
CLLocation an immutable class with respect to latitude and longitude. So you cannot modify its latitude. You have to create a new object:
[[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
Being immutable is the whole meaning of having such an initializer.
Upvotes: 6
Reputation: 1745
I'm no Objective-C expert, but I understand it's a C-superset... so shouldn't it be:
myPlace->publicLocation->coordinate.latitude
(with "->" instead of ".", I don't know for "coordinate", if it's a pointer or not )
Edit: Also, your program is very likely to crash if you try to access the attributes of a non-allocated object, myPlace in your case is not allocated.
Edit 2: see johne's comment below for why my answer should be ignored. (I'm leaving it though as it might serve someone someday making the same mistake)
Upvotes: 0
Reputation: 7084
As best as I can figure out, the compiler thinks I'm assigning to a read only variable.
You are attempting to assign to a read only property:
@property(readonly, nonatomic) CLLocationCoordinate2D coordinate;
Upvotes: 0
Reputation: 5654
coordinate
is defined as a read-only property of CLLocation
... so it appears you need to make a new CLLocation
rather than changing the coordinate value of an existing one.
Upvotes: 0