• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CORE DATA: open last used document ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CORE DATA: open last used document ??


  • Subject: Re: CORE DATA: open last used document ??
  • From: "Pierce T. Wetter III" <email@hidden>
  • Date: Thu, 23 Mar 2006 08:56:44 -0700


On Mar 22, 2006, at 5:09 PM, dan pahlajani wrote:

Hello everyone,

How do I open the last used document while using Core Data --
NSPersistenDocument?

Before the days of Core Data, I was able to do so in the app delegate by
accessing the recent docs array. With NSPersistenDocument I don't know which
message I should send to it once I have the file's URL.

I'm doing it this way:

in AppController.m:

- (BOOL) applicationShouldOpenUntitledFile: (NSApplication *) sender
{
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"lastFileURL"])
return NO;
return YES;
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
if ([[[NSDocumentController sharedDocumentController] documents] count]==0)
{
NSData *fileURLData=[[NSUserDefaults standardUserDefaults] objectForKey:@"lastFileURL"];
if (fileURLData)
{
NSError *error;
NSURL *fileURL=[NSUnarchiver unarchiveObjectWithData: fileURLData];
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL: fileURL
display: YES
error: &error];

}


in My document.m

- (BOOL)writeToURL:(NSURL *)absoluteURL
ofType:(NSString *)typeName
forSaveOperation:(NSSaveOperationType)saveOperation
originalContentsURL:(NSURL *)absoluteOriginalContentsURL
error:(NSError **)error
{
[[[NSUserDefaultsController sharedUserDefaultsController] values] setValue: [NSArchiver archivedDataWithRootObject: absoluteOriginalContentsURL] forKey:@"lastFileURL"];
return [super writeToURL: absoluteURL
ofType: typeName
forSaveOperation: saveOperation
originalContentsURL: absoluteOriginalContentsURL
error: error];
}



That is, when someone saves a file, I store the URL in the preferences file. In "shouldOpenUntitledFile" I look for the URL and return NO if there is one stored, and in applicationDidFinishLuanching I tell the document controller to open that URL.



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: CORE DATA: open last used document ??
      • From: "dan pahlajani" <email@hidden>
References: 
 >CORE DATA: open last used document ?? (From: "dan pahlajani" <email@hidden>)

  • Prev by Date: Re: CD: Predicate Builder - specifying NULL relationship
  • Next by Date: Re: CD: Predicate Builder - specifying NULL relationship
  • Previous by thread: CORE DATA: open last used document ??
  • Next by thread: Re: CORE DATA: open last used document ??
  • Index(es):
    • Date
    • Thread