문제

장치에 PLIST를 저장하는 올바른 FilePath는 무엇입니까?

튜토리얼

에서이 작업을 읽었습니다. 컴퓨터에서 작동하는

는 장치의 파일 위치를 알고 싶습니다.

// write xml representation of dictionary to a file
[dictionary writeToFile:@"/Users/henrik/Sites/foo.plist" atomically:NO];
.

현재 filepath에서

에서 읽으려고합니다.
NSString *filepath = [[NSBundle mainBundle] 
                      pathForResource:@"UserAdded" ofType:@"plist"];
userAddedQuotes = [[NSMutableArray alloc] initWithContentsOfFile:filepath];
.

다음과 같이

[userAddedQuotes addObject:temp];
    [userAddedQuotes writeToFile:filepath atomically: NO];
.

배열은 런타임에 업데이트되지만 PLIST에 저장되지 않습니다.

도움이 되었습니까?

해결책

응용 프로그램 번들 (자원 디렉토리 포함) 안에있는 모든 파일에 쓸 수 없습니다.파일을 작성하려는 경우 파일이있는 것에 따라 앱 문서 또는 라이브러리 폴더를 작성해야합니다.예 :

NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
.

는 첫 번째 문서 디렉토리 인 경로 배열을 반환합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top