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 protected])

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/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to