Re: How to write a dictionary into an output file
Re: How to write a dictionary into an output file
- Subject: Re: How to write a dictionary into an output file
- From: "Michael Ash" <email@hidden>
- Date: Mon, 5 Jun 2006 19:08:50 -0400
On 6/5/06, Julio Bianco <email@hidden> wrote:
Hi,
I'm trying to write son dictionary information in a file, and I
realize that I can do it using the method
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
and I use it like this:
+(TCLogger *) instance {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *LogFile1 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"one", [NSNumber numberWithInt: 1],
nil];
if ([LogFile1 writeToFile: @"/Users/jbianco/pueba.log" atomically:
YES])
The documentation on this method states:
"This method recursively validates that all the contained objects are
property list objects...."
If you follow the link to the "Property List Programming Guide" just
below that quote and read "About Property Lists", you will find the
following:
"Although dictionary keys in NSDictionary and CFDictionary are defined
to be an object of any type, for property lists they must be string
objects."
By creating a dictionary that uses an NSNumber as a key, you are
creating a dictionary that is not a valid property list, and therefore
can't be saved using that method. Either use only string keys, or look
into using NSKeyedArchiver instead.
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