Re: Usage of NSKeyedArchiver
Re: Usage of NSKeyedArchiver
- Subject: Re: Usage of NSKeyedArchiver
- From: Mike Abdullah <email@hidden>
- Date: Fri, 31 Mar 2006 20:40:09 +0100
Thanks Kirk and Daniel, it's always good to know when you're not
heading off in completely the wrong direction! :)
Mike.
On 31 Mar 2006, at 15:14PM, Kirk Kerekes wrote:
I have implemented encodeWithCoder: in myObject and using
NSKeyedArchiver can successfully place the thing on disk.
So, basically what this boils down to is, is NSKeyedArchiver the man
for the job?
Sure, so long as you don't have any NSValue objects that your
object archives. For no good reason, NSKeyedArchiver won't archive
any NSValue entities, not even the "standard" ones like NSRange,
NSPoint, etc. This is easy enough to sidestep in your own objects
(just use NSStringFromXXX() to convert the NSXXX data into an
NSString, and archive that) but it can really bite you if you want
to store something created by COCOA that happens to have a NSValue
internally, like a printer setup document.
NSArchiver does handle NSValue, by the way, but I don't know how
endian-aware the code is.
When I look at the file produced by my experimental
archiveRootObject:toFile: things aren't as simple as I had expected -
there's a lot of "mysterious" values in there which seem to be part
of how NSKeyedArchiver works.
They are all documented, but you don't need to know about them.
There is no need to be poking around inside an archive. There are
several internal archive formats, and the potential for more. A
NSKeyedArchive is a property list, which can (in principle) be
created in either text or binary form. All of this is transparent
if you just stick to the Cocoa interface.
If I store this in my plist file, I want to be able to retrieve a
string "summary" of myObject without actually instanciating
Save a separate item using some sort of computed-key scheme to
associate the summary with the object as in "savedObject1"
associates with "savedObject1_Summary".
myObject. Should I still use NSKeyedArchiver for this and store the
summary string outside of the NSKeyedArchiver result and just
"associate" the two in the plist?
Sure, as above. Or group the object's archived data and its
description in a NSDictionary and add that to the your NSArray of
saved items in the user defaults. I suggest that you might also
consider adding some other metadata items to the object dictionary
-- like creation and modification dates, etc. Save dates as
strings, using the relevant NSDate methods.
Mike.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden