iphone - Can't set property with custom setter -
iphone - Can't set property with custom setter -
i've tried implement next locationmanager:
starting update users location
- (void)startstandardupdates { if (self.locationmanager == nil) { self.locationmanager = [[cllocationmanager alloc] init]; } self.locationmanager.delegate = self; self.locationmanager.desiredaccuracy = kcllocationaccuracybest; // set motion threshold new events self.locationmanager.distancefilter = kcllocationaccuracynearesttenmeters; [self.locationmanager startupdatinglocation]; cllocation *currentlocation = self.locationmanager.location; if (currentlocation) { self.currentlocation = currentlocation; } }
implementing custom setter property send notifications
- (void)setcurrentlocation:(cllocation *)currentlocation { self.currentlocation = currentlocation; nslog(@"%f", currentlocation.coordinate.latitude); //notify app of location alter nsdictionary *userinfo = [nsdictionary dictionarywithobject:self.currentlocation forkey:kiflocationkey]; dispatch_async(dispatch_get_main_queue(), ^{ [[nsnotificationcenter defaultcenter] postnotificationname:kiflocationchangenotification object:nil userinfo:userinfo]; }); }
the problem is: when run app, "bad_exec (code 2)" error message in "setcurrentlocation" method in debug mode , app has hung up. don't issue. did miss out? far see it, in "startstandardupdates", if location manager has found user's location, property "currentlocation" beingness updated, using custom setter "self.currentlocation = currentlocation".
thanks help in advance! regards sebastian
the way implemented setter problem. self.currentlocation = ... causes setter called , phone call while implementing setter, causing infinite loop. synthesize ivar below, , utilize _variablename in setters (and getters).
@synthesize currentlocation = _currentlocation;
//setter
- (void)setcurrentlocation:(cllocation *)currentlocation { _currentlocation = currentlocation; nslog(@"%f", currentlocation.coordinate.latitude); //notify app of location alter nsdictionary *userinfo = [nsdictionary dictionarywithobject:self.currentlocation forkey:kiflocationkey]; dispatch_async(dispatch_get_main_queue(), ^{ [[nsnotificationcenter defaultcenter] postnotificationname:kiflocationchangenotification object:nil userinfo:userinfo]; }); }
iphone properties location core-location
Comments
Post a Comment