PDA&Mobile2010/02/12 12:57
* 본 포스트는 Blog.MissFlash.com에서 작성한 것으로, 원문 저작자의 동의없이 마음대로 퍼가실 수 없습니다. 포스트의 내용이 마음에 드시면 링크를 이용해주시면 감사하겠습니다.

> Stanford Lecture #9

* Reading property lists
- (id)initWithContentsOfFile:(NSString *)aPath;
- (id)initWithContentsOfURL:(NSURL *)aURL;

* Writing property lists
- (BOOL)writeToFile:(NSString *)aPath atomically:(BOOL)flag;
- (BOOL)writeToURL:(NSURL *)aURL atomically:(BOOL)flag;

* Writing an array to disk
NSArray *array = [NSArray arrayWithObjects:@"Foo", [NSNumber numberWithBool:YES], [NSDate dateWithTimeIntervalSinceNow:60], nil];
[array writeToFile:@"MyArray.plist" atomically:YES];

* Writing a dictionary to disk
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"Evan", @"Lecture", [NSNumber numberWithInt:9], nil];
[dict writeToFile:@"MyDict.plist" atomically:YES];

* Property list to NSData
+ (NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format errorDescription:(NSString *)errorString;

* NSData to property list
+ (id)propertyListFromData:(NSData *)data mutabilityOption:(NSPropertyListMutabilityOptions)opt format:(NSPropertyListFormat *)format errorDescription:(NSString *)errorString;



* Basic directories
NSString *homePath = NSHomeDirectory();
NSString *tmpPath = NSTemporaryDirectory();

* Documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

* <Application Home>/Documents/foo.plist
NSString *fooPath = [documentsPath stringByAppendingPathComponent:@"foo.plist"];



* Encode an object for an archive
- (void)encodeWithCoder:(NSCoder *)coder{
[super encodeWithCoder:coder];
[coder encodeObject:name forKey:@"Name"];
[coder encodeInteger:numberOfSides forKey:@"Sides"];
}

* Decode an object from an archive
- (id)initWithCoder:(NSCoder *)coder{
self = [super initWithCoder:coder];
name = [[coder decodeObjectForKey:@"Name"] retain];
numberOfSides = [coder decodeIntegerForKey:@"Sides"];
}

* Creating an archive
NSArray *polygons = ...;
NSString *path = ...;
BOOL result = [NSKeyedArchiver archiveRootObject:polygons toFile:path];

* Decoding an archive
NSArray *polygons = nil;
NSString *path = ...;
polygons = [NSKeyedUnarchiver unarchiveObjectWithFile:path];



* Open the database
int sqlite3_open(const char *filename, sqlite3 **db);

* Execute a SQL statement
int sqlite3_exec(sqlite3 *db, const char *sql, int (*callback)(void*, int, char**, char**), void *context, char **error);

* Close the database
int sqlite3_close(sqlite3 *db);



* Options for parsing XML
libxml2 vs. NSXMLParser

* Reading a JSON string into Foundation objects
#import <JSON/JSON.h>
NSString *jsonString = ...;
id object = [jsonString JSONValue];

* Writing a JSON string from Foundation objects
NSDictionary *dictionary = ...;
jsonString = [dictionary JSONRepresentation];
저작자 표시 비영리 변경 금지

이 글은 새로운 정보가 추가될 때마다 업데이트됩니다. 추천으로 아래 숫자에 1을 더해보세요. :)
RSS구독을 하시면 포스트를 배달해 드립니다. ▷ 한RSS 구독하기, 구글리더 구독하기

TRACKBACK http://blog.missflash.com/trackback/628 관련글 쓰기

댓글을 달아 주세요