티스토리 뷰
컬렉션 프로퍼티 리스트 클래스 (NSArray, NSDictionary)는 프로퍼티 리스트를 파일로 기록해주는
- writeToFile: atomically: 메소드를 가지고 있다.
NSArray *phrase;
phrase = [NSArray arrayWithObjects: @"Hello", @"my", @"name", @"is", @"jesica", nil];
[phrase writeToFile: @"/tmp/test.txt" atomically: YES];
위 소스는 xml 파일 형식으로 Hello, my, name, is, jesica 를 순차적으로 저장한다.
저장된 test.txt 파일은 + arrayWithContentsOfFile: 메소드로 읽을 수 있다.
NSArray *phrase2 = [NSArray arrayWithContentsOfFile: @"/tmp/test.txt"];
NSLog (@"%@", phrase2);
이들 함수의 단점은 에러 정보를 전혀 반환하지 않는다.
파일을 읽을 수 없으면 nil 포인터를 받게 될 것이다.
- writeToFile: atomically: 메소드를 가지고 있다.
NSArray *phrase;
phrase = [NSArray arrayWithObjects: @"Hello", @"my", @"name", @"is", @"jesica", nil];
[phrase writeToFile: @"/tmp/test.txt" atomically: YES];
위 소스는 xml 파일 형식으로 Hello, my, name, is, jesica 를 순차적으로 저장한다.
저장된 test.txt 파일은 + arrayWithContentsOfFile: 메소드로 읽을 수 있다.
NSArray *phrase2 = [NSArray arrayWithContentsOfFile: @"/tmp/test.txt"];
NSLog (@"%@", phrase2);
이들 함수의 단점은 에러 정보를 전혀 반환하지 않는다.
파일을 읽을 수 없으면 nil 포인터를 받게 될 것이다.
'나름 프로그래밍? > Objective-C' 카테고리의 다른 글
하이브리드 아이폰 애플리케이션 개발 (0) | 2010.02.19 |
---|---|
iPhone SDK 에서 계산기 만들기 (2) | 2010.02.17 |
NSDate 와 NSData (0) | 2010.02.10 |
@property (0) | 2010.02.08 |
클래스 메소드 (0) | 2010.02.05 |