Re: NSKeyedArchiver not saving as binary data
Re: NSKeyedArchiver not saving as binary data
- Subject: Re: NSKeyedArchiver not saving as binary data
- From: "Matt R" <email@hidden>
- Date: Thu, 8 Feb 2007 14:18:26 -0800
I hope I'm not overlooking something silly, but the code I posted, when run
on my 10.4.8 system under Xcode 2.4.1, produces a 180byte file that is, as
far as I can tell, an XML file. Perhaps I don't understand these definitions
but what I was expecting was a smaller-sized file that didn't contain the
full XML verbose language, and instead was a more compact binary version
which wouldn't be readable in a normal text editor. But regardless of which
setOutputFormat setting I use, if I drag the saved file to a text editor and
it comes up with the following output (some of the values below are just
dummy values placed into the test variables)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "
http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>$archiver</key>
<string>NSKeyedArchiver</string>
<key>$objects</key>
<array>
<string>$null</string>
<string>Cornelius</string>
</array>
<key>$top</key>
<dict>
<key>integerA</key>
<integer>5</integer>
<key>integerB</key>
<integer>10</integer>
<key>stringA</key>
<dict>
<key>CF$UID</key>
<integer>1</integer>
</dict>
</dict>
<key>$version</key>
<integer>100000</integer>
</dict>
</plist>
On 2/8/07, Ali Ozer <email@hidden> wrote:
Are you sure this code is actually writing a new file for you? The
code you posted works fine for me on 10.4.8 and generates a binary file.
Ali
Begin forwarded message:
> From: Matt R <email@hidden>
> Date: February 8, 2007 11:24:08 AM PST
> To: email@hidden
> Subject: NSKeyedArchiver not saving as binary data
>
> Perhaps i'm overlooking something obvious, as is usually the case,
> but I
> cannot get my instance of NSKeyedArchiver to save my files as
> binary data. I
> use setOutputFormat to set it to the binary option, and I've tried
> the other
> settings as well, and have also experimented with re-ordering the
> code, but
> in every case my data is written in a very verbose XML format, and
> for a
> number of reasons I need just the raw binary data written to the
> file. Can
> anyone see what I'm doing wrong here and enlighten me as to my
> mistake? This
> test code is straight from an example in the apple docs ('Archives and
> Serializations Programming Guide for Cocoa'), and works fine and
> saves the
> proper data, but just in the wrong format.
>
> any thoughts? thank you
> -matt
>
> NSMutableData *data;
> NSKeyedArchiver *archiver;
> BOOL result;
>
> data = [NSMutableData data];
> archiver = [[NSKeyedArchiver alloc]
> initForWritingWithMutableData:data];
> [archiver setOutputFormat:NSPropertyListBinaryFormat_v1_0];
>
> [archiver encodeObject:myString forKey:@"stringA"];
> [archiver encodeInt:variable1 forKey:@"integerA"];
> [archiver encodeInt:variable1 forKey:@"integerB"];
> [archiver finishEncoding];
>
> result = [data writeToFile:filePath atomically:YES];
> [archiver release];
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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