Re: Where To Put Export... In Document-Based Core Data App
Re: Where To Put Export... In Document-Based Core Data App
- Subject: Re: Where To Put Export... In Document-Based Core Data App
- From: Gideon King <email@hidden>
- Date: Mon, 15 Feb 2010 15:15:12 +1000
You're probably missing the concept of the responder chain. Yes, it should be defined in your document, and hooked up in your menu to the first responder.
Then when you have a document there, it will receive the message and be able to process it with its own data. You get the automatic enabling of the menus etc for free.
HTH
Gideon
On 15/02/2010, at 4:23 AM, steve ross wrote:
> 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?
>
_______________________________________________
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