Where To Put Export... In Document-Based Core Data App
Where To Put Export... In Document-Based Core Data App
- Subject: Where To Put Export... In Document-Based Core Data App
- From: steve ross <email@hidden>
- Date: Sun, 14 Feb 2010 10:23:19 -0800
I have a document-based CoreData app, which means there could be several docs open at once. I want to implement Export As CSV... (but not as a "supported file type," as this is one-way only). Being a Cocoa n00b, I'm struggling with where to put the action in a class that is current-document aware. I thought MyDocument.m (note the creative naming :) would make sense for toCSV(), but I can't hook a controller action up to the main menu in IB. The code:
- (IBAction) onExportToCSV:(id)sender
{
NSManagedObjectContext * moc = [self managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSError *error;
NSArray *result = [moc executeFetchRequest:request error:&error];
// File saving stuff goes here...
}
Questions:
- Is the document class the right place? It makes sense to me that the document would know how to save itself
- Would the controller, instead, want to tell the document to persist itself as CSV?
- How can I hook a File > Export... menu item to a controller action. I can hook it to AppController and then send a message but it seems hacky.
- [OT] This targets Snowy only. Do I really need to use release and autorelease if I turn on GC mandatory?
Thanks_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden