2011年5月19日 星期四

Foundation Framework-歸檔 CH19-1 XML Property List

//

// main.m

// CH19-1 XML Property Lists

//

// Created by jason on 2011/5/18.

// Copyright 2011 __MyCompanyName__. All rights reserved.

//

// 物件如果是 NSString , NSDictionary , NSArray , NSDate, NSData, NSNumber型態 可以使用writeToFile: atomically: 方法將資料寫入檔案

//

#import

#import

#import

#import


//#import


int main(int argc, char *argv[])

{

NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];

NSDictionary *glossary=[NSDictionary dictionaryWithObjectsAndKeys:@"Apple Inc. is an American multinational corporation that designs and markets consumer electronics, computer software, and personal computers.", @"Apple Inc.",

@"Steven Paul ""Steve"" Jobs (born February 24, 1955) is an American business magnate and inventor. He is the co-founder and chief executive officer of Apple Inc.", @"Steve Jobs",

@"The Macintosh, or Mac, is a series of several lines of personal computers designed, developed, and marketed by Apple Inc.",@"Macintosh",nil];

if([glossary writeToFile:@"glossary" atomically:YES]==NO) // "writeToFile:atuimically:encoding: error: " 將辭典以property list 形式寫入檔案 glossary

// 參數 atomically :YES 表示寫入時會使用暫存檔,若寫到一半當機, 原始檔案不會不見!

NSLog(@"Save to file failed!");

[pool drain];

return 0;

// return NSApplicationMain(argc, (const char **) argv);

}

沒有留言: