Re: Copying Managed Objects from App to Doc MOContext
Re: Copying Managed Objects from App to Doc MOContext
- Subject: Re: Copying Managed Objects from App to Doc MOContext
- From: Jerry Krinock <email@hidden>
- Date: Tue, 28 Jul 2009 17:36:24 -0700
On 2009 Jul 28, at 16:07, Ben Trumbull wrote:
Accessor methods don't accept NSNull in place of NSString.
Yes.
I think I understand this now -- I was having trouble with your terms
"copy/snapshot" and "restore".
Accessor methods don't accept NSNull...the swapping has to happen in
your copy/snapshot code.
Thinking about this further, I realize that my purpose is simply
copying a managed object from one managed object context to a
different managed object context, and this is effectively a copy-and-
paste. So, I looked at how copy and paste is done in
DepartmentAndEmployees. In -[MyDocument copy:], they produce a
dictionary using -[NSKeyValueCoding dictionaryWithValuesForKeys], in
which "Entries for which -valueForKey: returns nil have NSNull as
their value in the returned dictionary." In -[MyDocument paste:],
they set values in the new object using -[NSKeyValueCoding
setValuesForKeysWithDictionary:], in which "Dictionary entries whose
values are NSNull result in -setValue:nil forKey:key messages being
sent to the receiver."
So, I believe what you mean by "swapping". These two NSKeyValueCoding
methods do it for you, if you're using a dictionary to transfer the
attributes.
The NSNull issue is unfortunate, but your alternative is not copying
nil values at all since they won't be in the dictionary.
Actually, in my implementation I happen to have a reference to the
existing object, so I just copy attributes in a loop -- there is no
dictionary. A nil value is "getted" and "setted" the same as a non-
nil value.
For creating new objects, that's not a problem.
Good!
But now it appears that you're discussing a different problem, one
that I'm not familiar with (but maybe should be)
But for restoring previous state over an existing object, that's
undesirable. There are other more complicated approaches, but
ultimately handling NSNull in your restore code is the least bad
approach.
In what practical situation would one want to be "restoring previous
state over an existing object"?
Thanks, Ben.
_______________________________________________
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