• 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
NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPersistentDocument: "Settings" (DepartmentsAndEmployees)


  • Subject: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
  • From: Jerry Krinock <email@hidden>
  • Date: Sat, 25 Oct 2008 08:15:57 -0700

In Apple's DepartmentsAndEmployees Sample Code project, the document (MyDocument) has this instance variable:

     NSManagedObject* department ;

I view this 'department' as special "Document Settings Ivar". There is always one and only one of them in each document. As a matter of fact, from the user's viewpoint, each document is a Deparment; the document is the Department and vice versa. It seems to me that most Core Data Document-Based Applications will have such a Document Settings Ivar in their Document. If the project were a word processor, for example, the Document Settings Ivar would store page size, margins, etc.

In DepartmentsAndEmployees, initWithType:error: is overridden to customize creation of new documents. I've copied the code here...

- (id)initWithType:(NSString *)type error:(NSError **)error
{
self = [super initWithType:type error:error];
if (self != nil)
{
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
[self setDepartment:[NSEntityDescription insertNewObjectForEntityForName:@"Department"
inManagedObjectContext:managedObjectContext]];


// To avoid undo registration for this insertion, removeAllActions on the undoManager.
// First call processPendingChanges on the managed object context to force the undo registration
// for this insertion, then call removeAllActions.
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager] removeAllActions];
[self updateChangeCount:NSChangeCleared];
}
return self;
}


Documentation for -processPendingChanges says "causes changes to registered managed objects to be recorded with the undo manager". Well, since the intent is "to avoid undo registration for this insertion", should not the -processPendingChanges message be sent ^before^ -setDepartment:? I made this change in the code, built, tested a new document with Undo and all seems to still work fine.

Actually, it seems that the -processPendingChanges message could simply be deleted because how could there be any other pending changes before -init anyhow?

Thanks,

Jerry Krinock
_______________________________________________

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


  • Follow-Ups:
    • Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Controlling Preference Panel Installation
  • Next by Date: Creating icons and other resources
  • Previous by thread: Re: Controlling Preference Panel Installation
  • Next by thread: Re: NSPersistentDocument: "Settings" (DepartmentsAndEmployees)
  • Index(es):
    • Date
    • Thread