saving data as a file in mac osx
Basically, i want to save NSData as a file using NSSaver. what do i add into my if statement to save it/what corrections should i make to this method?
- (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] == NSOK开发者_JS百科Button){
}
}
Error handling code omitted.
[data writeToURL:[saver URL] atomically:YES];
精彩评论