views:

281

answers:

1

I've defined this subclass of CLLocation

MyLocation.h

@interface MyLocation: CLLocation {
    NSString *datum;
    NSString *ellipsoid;
}

@property(nonatomic,retain) NSString *ellipsoid;
@property(nonatomic,retain) NSString *datum;

MyLocation.m

@synthesize datum,ellipsoid;

Now i get a CLLocation instance through the location manager delegate

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ //self.myPosition is a MyLocation myPosition; self.myPosition = newLocation; [myPosition setDatum: @"WGS 84"]; [myPosition setEllipsoid: @"WGS 84"]; }

When i do the self.myPosition = newLocation i get an UNCAUGHT EXCEPTION and it dies

I've also tried this way with same results:

self.myPosition = (MyLocation *)newLocation;
A: 

newLocation is not an instance of ur subclass so doing that assignment or casting throws an error because it's an invalid cast, u should be seting the values of ur subclass that u want fromthe cllocation object something like

self.myPosition=[[MyLocation alloc] initWithCoordinate:newLocation.coordinate]

and so on

Daniel
Problem is all the properties in CLLocation are readonly
Jorge
Right so use intWithCoordinate instaed
Daniel
Check out the edit
Daniel