如何创建文件.plist

时间:2014-04-02 03:44:27

标签: ios nsarray 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 感谢。

4 个答案:

答案 0 :(得分:0)

您应该使用NSDictionary来创建.plist文件。 阅读此Apple教程以获取更多详细信息: https://developer.apple.com/library/ios/documentation/cocoa/conceptual/PropertyLists/CreatePropListProgram/CreatePropListProgram.html

答案 1 :(得分: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];

答案 2 :(得分:0)

您的解决方案在于此链接 - http://iosdevhelper.blogspot.in/2011/04/plists.html

彻底完成它,它还有示例代码行。

希望有所帮助。

答案 3 :(得分: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];

乐意帮助