2014-06-17 2 views
0

개발은 iOS 용 Xcode에 있습니다. 나는 2 개의 분리 된 NSmutabledictionary를 사용했다. (I가 종종 발견 검색 할 때,하지만 그건 내가 할 무엇을하려고하지 않습니다)디스크에 2 NSMutableDictionary를 저장하는 방법

I하지는 그들을 추가 할

앱이 디스크와 앱을 출시 할 때 수에 저장할한다 사전을 읽으십시오. 그것은 사용자 정의 클래스 그래서 initWithCoder 아니며, 다른 하나는 필요하지 않습니다이 작동

NSArray *data = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *path = [data objectAtIndex:0]; 
path = [path stringByAppendingPathComponent:@"location"]; 
[NSKeyedArchiver archiveRootObject:"Dictionary" toFile:path]; 

(?이 권리입니다)하지만 난 다른 사전을 저장할 때 작동하지 않습니다. 내 첫 번째 생각은 objectAtIndex를 1로 변경하는 것입니다. 그러나 Xcode는 제가 그렇게 할 때 저에게 오류를줍니다. 다른 이름 만 지정하면 저장되지 않지만 Xcode는 오류를주지 않습니다.

내가 뭘 잘못하고 있니?

+0

사용 NSUSerDefaults을 디스크에 데이터를 저장 – Jatin

답변

0
// Find out where the documents folder is 
NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; 
// Create the file path for a file named 'location' inside the documents folder 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"location"]; 

// Write an array containing both of your arrays to a file at that path 
[NSKeyedArchiver archiveRootObject:@[myFirstArray, mySecondArray] toFile:path]; 

그런 다음,이를 다시 읽기 :

// Read back the array containing the two arrays 
NSArray *arrays = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 

// Get the individual arrays from the array 
NSMutableArray *myFirstArray = arrays[0]; 
NSMutableArray *mySecondArray = arrays[1]; 
관련 문제