2013-02-09 4 views
0

사용자 정의 세터와 속성을 설정할 수 없습니다내가 내을 locationManager과 다음 구현하기 위해 노력했습니다

- (void)setCurrentLocation:(CLLocation *)currentLocation { 
    self.currentLocation = currentLocation; 
    NSLog(@"%f", currentLocation.coordinate.latitude); 

    //Notify the app of the location change 
    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:self.currentLocation forKey:kIFLocationKey]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [[NSNotificationCenter defaultCenter] postNotificationName:kIFLocationChangeNotification object:nil userInfo:userInfo]; 
    }); 
} 

문제는 : 내가 응용 프로그램을 실행할 때, 내가 디버그 모드와 t에서 "setCurrentLocation"방법에서 "BAD_EXEC (코드 2)"오류 메시지가 그는 앱이 끊겼다. 그러나 나는 그 문제를 이해하지 못한다. 뭔가 빠져 나왔어? "startStandardUpdates"에서 위치 관리자가 사용자의 위치를 ​​찾으면 사용자 정의 setter "self.currentLocation = currentLocation"을 사용하여 "currentLocation"속성이 업데이트되고 있습니다.

미리 도움을 주셔서 감사합니다. 안부 세 바스 챤

답변

2

세터를 구현 한 방식이 문제입니다. self.currentLocation = ... setter가 호출되도록하고 setter를 구현하는 동안 무한 루프를 발생시키는 호출합니다. 다음과 같이 ivar을 합성하고 setter (및 getter)에서만 _variablename을 사용하십시오.

@synthesize currentLocation = _currentLocation;

// 세터

- (void)setCurrentLocation:(CLLocation *)currentLocation { 
    _currentLocation = currentLocation; 
    NSLog(@"%f", currentLocation.coordinate.latitude); 

    //Notify the app of the location change 
    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:self.currentLocation forKey:kIFLocationKey]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [[NSNotificationCenter defaultCenter] postNotificationName:kIFLocationChangeNotification object:nil userInfo:userInfo]; 
    }); 
} 
관련 문제