0

내 응용 프로그램에서 나중에 사용할 수 있도록 내 CLLocation 위치를 저장하려고합니다. 내 응용 프로그램을 실행하면CLLocation을 더 잘 저장하려면 어떻게해야합니까?

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"/Locations.plist"]; 
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path]; 

[data setValue:[NSKeyedArchiver archivedDataWithRootObject:location] forKey:@"LocationList"]; 
[data writeToFile:path atomically:YES]; 

NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData: (NSData *)[data objectForKey:@"LocationList"]]]; 
    NSLog(@"%@",array); 

이 컴파일러는 내가 잘못하고있는 중이 야 무엇

-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL 

를 반환 : 나는 다음과 같이 올라와있다? 또는 CLLocation 데이터를 저장하는 더 나은 표준 방법이 있습니까?

+0

특별히 NSKeyedArchiver를 사용하지 않으시겠습니까? 아니면 CoreData를 사용하는 것이 합리적입니까? 당신의 유스 케이스는 무엇입니까? – Chris

답변

0

메소드가 실제로 리턴하는 것을 추적하지 못했기 때문에 여러 메시지 호출을 서로 내부에 임베드 할 때 위험합니다.

당신은 CLLocation을 저장, 그래서 이것은 CLLocationObject 반환

: 배열 NULL 왜

NSMutableArray *array = [[NSMutableArray alloc] initWithArray:... // Your returned CLLocation here. 

: 그것은 배열을 반환 된 것처럼

[NSKeyedUnarchiver unarchiveObjectWithData: (NSData *)[data objectForKey:@"LocationList"]] 

당신의 코드가 치료된다 . CLLocation 데이터를 저장하는 방법은 인코딩 방식이 정확합니다. (this answer for a clear reference to storing CLLocations as NSData objects을 참조하십시오.)