我查看了 SDK 文档和其他被问到的问题,但我仍然对如何做到这一点感到有些困惑。我以前一直在使用以下代码,尽管它没有给出 .plist 文件的预期结果。除了在 .m 文件中的这段代码中的头文件中提到 IBAction 之外,还有什么需要添加的或者我应该采用的方法吗?谢谢!
我的代码:
- (IBAction)fedDog {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dogsFedDays.plist"];
NSMutableArray *dogsFedSave = [NSMutableArray arrayWithCapacity: 100];
for (int i = 0; i < 100; i++) {
NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:
date[i], @"string",
fed[i], @"Yes",
nil];
[dogsFedSave addObject:myDict];
[myDict release];
}
if (![dogsFedSave writeToFile:path atomically:YES])
NSLog(@"not successful in completing this task");
}