写入位于iPhone资源文件夹中的plists

时间:2010-03-19 16:43:49

标签: iphone objective-c cocoa-touch

任何人请回答我,如何写入位于我的资源文件夹中的plist文件。请为我写一个示例代码。

2 个答案:

答案 0 :(得分:6)

你做不到。应用程序包在iPhone OS设备上无法写入。

答案 1 :(得分:1)

-(IBAction)textFieldCheck:(id) sender {
    myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6]retain];
    NSArray *keys = [NSArray arrayWithObjects:@"Date",@"Time",@"Address",@"City",@"State",@"Zipcode",nil];
    [myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
                                                                  [NSString stringWithFormat:@"%@",txtDate.text], 
                                                                  [NSString stringWithFormat:@"%@",txtTime.text], 
                                                                  [NSString stringWithFormat:@"%@",txtAddress.text], 
                                                                  [NSString stringWithFormat:@"%@",txtCity.text], 
                                                                  [NSString stringWithFormat:@"%@",txtState.text], 
                                                                  [NSString stringWithFormat:@"%@",txtZip.text],nil]forKeys:keys]];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myPrimaryinfo.plist"];
    [myPrimaryinfo writeToFile:path atomically:NO];
    NSLog(@"PrimaryInfo array: %@", myPrimaryinfo); 
}