2014-04-02 81 views
0

如何創建.plist文件。數據結構應該是什麼?如何創建文件.plist

我嘗試這樣做:

Story * story1 = [Story new]; 
story1.name = @"title"; 
story1.read = @"read total"; 
story1.callme = @"Tel"; 
story1.image = @"http://url image /0490_web.gif"; 
story1.details = @"content details"; 

平臺的NSArray 感謝。

回答

0
NSMutableArray *stories = [NSMutableArray new]; 

    NSArray *keys = [NSArray arrayWithObjects:@"name", @"read", @"callme", @"image", @"details", nil]; // Set the key values for each field 

    // Create a story dict and add them to the array 
    [stories addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"title", @"read total", @"Tel", @"http://url image /0490_web.gif",@"content details", nil] forKeys:keys]]; 

    //If u need to add second details repeat the above step 
    // Saving .plist file 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName.plist]; 
[stories writeToFile:filePath atomically:YES]; 
+0

你不能寫入mainbundle。 http://stackoverflow.com/questions/7689904/writing-nsarray-back-to-plist?rq=1 – Ramdy

+0

@Ramdy你是對的,謝謝 – LML

+0

如果你接受我的答案,請upvote。它會被使用。 – Ramdy

0

試試這個代碼,

NSMutableArray * ArrayDetail = [[NSMutableArray alloc]init]; 

    ArrayDetail= [NSMutableArray arrayWithObjects:story1.name,story.read,story.callme,story1.image, story.details, nil]; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"yourPlistName.plist"]; 

[ArrayDetail writeToFile:filePath atomically:YES]; 

快樂幫

+0

如果您對此有任何疑問,請詢問。 – Ramdy