Re: Managed Object with Transformable Attribute (C Struct)
Re: Managed Object with Transformable Attribute (C Struct)
- Subject: Re: Managed Object with Transformable Attribute (C Struct)
- From: Richard Somers <email@hidden>
- Date: Tue, 15 Dec 2009 23:12:47 -0700
On Dec 15, 2009, at 10:06 PM, Graham Cox wrote:
You're creating an archive-within-an-archive and an archive is just
a block of binary data by default. If you set the output format type
of your secondary archive to XML, you'll be able to see the keys,
but it will still be a separate second archive within the main one.
Thanks for the clarification but I do not fully understand part of
your comment. The value of 'foo' comes into -(id)transformedValue:
(id)value as a NSConcreteValue instance. The frameworks automatically
wrap it thus. In my new implementation of this method I get the value
of 'foo' back into a struct and encode with the keyed archiver. It is
then sent out as NSData (thanks to your corrections) archived only a
single time directly from the struct. So just a single archive is sent
into the Core Data store. So I don't understand what you mean by an
archive-within-an-archive. Sorry if this is a dumb question.
If you don't want to archive as a secondary archive, implement -
initWithCoder for your 'Foo' object (you'll need to make it into an
object supporting NSCoding) and write its members individually. I'd
suggest that anyway rather than using simple structs, precisely to
avoid the problem you've been having.
I was trying to emulate what Apple does with NSRect, NSSize, NSPoint,
etc. I thought if Apple can get the Cocoa frameworks to work with
simple structs then why can't I.
My struct 'Foo' really wants to be a struct not a class, I think. It
is used in a lot of heavy duty math calculations and functions but I
also need to save it to the persistent store.
Perhaps I should try using two attributes, one transient and the other
a "shadow" representation. The documentation for 10.5 seems to favor
transformable attributes for non-standard persistent attributes. I was
initially successful using a transformable attribute with a simple
custom value transformer using NSArchiver so I thought I was on the
right track. Every thing worked but the save document as binary.
--Richard
_______________________________________________
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