Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: how to prevent document being dirtied when chaging attributes?



On 1/17/08 5:34 PM, Felix Franz said:

>> In a Core Data app, how should one model a property of an object
>> that a)
>> should be saved as part of the document b) should not participate in
>> undo c) should not dirty the document when changed and d) can be
>> easily
>> bound to?
>
>disabling undo-registration (as described in "Undo Management" <http://
>developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/
>cdUsingMOs.html#//apple_ref/doc/uid/TP40001803-207821-TPXREF148
> >) should do the trick. I see no reason
>why disabling undo-registration should break bindings in any way.

Felix,

Thanks for the link.  I had tried something like that with limited
success, but was missing the critical processPendingChanges.

So is it typical to do such a thing in an NSManagedObject subclass' KVC
setter?  Like so:

- (void)setName:(NSString*)value_
{
	NSManagedObjectContext* moc = [self managedObjectContext];
	NSUndoManager* undoMan = [moc undoManager];
	
	[moc processPendingChanges];
	[undoMan disableUndoRegistration];

	[self willChangeValueForKey:@"name"];
	[self setPrimitiveValue:value_ forKey:@"name"];
	[self didChangeValueForKey:@"name"];

	[moc processPendingChanges];
	[undoMan enableUndoRegistration];
}

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Core Data: how to prevent document being dirtied when chaging attributes? (From: "Sean McBride" <email@hidden>)
 >Re: Core Data: how to prevent document being dirtied when chaging attributes? (From: Felix Franz <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.