将数据保存为mac osx中的文件

时间:2011-06-21 17:02:31

标签: objective-c xcode macos

基本上,我想使用NSSaver将NSData保存为文件。我要添加到我的if语句中以保存它/我应该对此方法进行哪些更正?

 - (IBAction)saveAs:(id)sender{

NSMutableArray *storage = [NSMutableArray arrayWithCapacity:[[arrayController arrangedObjects] count]];
for (int i = 0; i < [[arrayController arrangedObjects] count]; i++) {
    Stores *object = [[arrayController arrangedObjects] objectAtIndex:i];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:object.Website, @"website",object.Street_Address, @"streetAddress", object.City_Address, @"cityAddress", object.Name, @"storeName", object.Latitude, @"latidude", object.Longitude, @"longitude", object.Phone_Number, @"phoneNumber", nil];
[storage addObject:dict];
}
NSData *data = [NSKeyedArchiver archiveDataWithRootObject:storage];
NSSavePanel *saver = [NSSavePanel savePanel];
saver.requiredFileType = @"yogurtstorelocations";
[saver runModal];
if ([saver runModal] == NSOKButton){


    }

}

1 个答案:

答案 0 :(得分:6)

错误处理代码被省略。

[data writeToURL:[saver URL] atomically:YES];