• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: write dictionary to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: write dictionary to file


  • Subject: Re: write dictionary to file
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Wed, 9 Apr 2003 08:37:15 +0200

--__--__--

Message: 9
Date: Tue, 08 Apr 2003 16:34:12 -0700
From: Esteban Uribe <email@hidden>
To: "Gerriet M. Denkmann" <email@hidden>
Subject: Re: write dictionary to file
Cc: email@hidden

Hi,

On Tuesday, April 08, 2003, at 01:35PM, Gerriet M. Denkmann <email@hidden> wrote:

When I run this small program:

id key = [ NSNumber numberWithInt: 42 ] ;
id value = @"the meaning of life" ;
id totalKnowledge = [ NSDictionary dictionaryWithObjectsAndKeys: value,
key, nil ] ;
if ( ![ totalKnowledge writeToFile: @"/tmp/abc.plist" atomically: YES ]
)
NSLog(@"confused");

I always get "confused".
I read the docs over and over again, but do not see anything wrong.
Is this a bug, or have I missed something?

Btw: it work of course with key = @"42".


I think the problem is that writeToFile only writes out keys that are NSStrings.
This same limitation does not apply to the object referred to by the key which
can be NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary objects.

-Esteban

This seems to be true. But where is it documented?


--__--__--

Message: 10
Date: Tue, 8 Apr 2003 17:06:36 -0500
From: Nicholas Riley <email@hidden>
To: "Gerriet M. Denkmann" <email@hidden>
Cc: email@hidden
Subject: Re: write dictionary to file

On Tue, Apr 08, 2003 at 10:35:31PM +0200, Gerriet M. Denkmann wrote:
When I run this small program:

id key = [ NSNumber numberWithInt: 42 ] ;
id value = @"the meaning of life" ;
id totalKnowledge = [ NSDictionary dictionaryWithObjectsAndKeys: value,
key, nil ] ;
if ( ![ totalKnowledge writeToFile: @"/tmp/abc.plist" atomically: YES ]
)
NSLog(@"confused");

I always get "confused".
I read the docs over and over again, but do not see anything wrong.
Is this a bug, or have I missed something?

You've missed something. From the docs:

writeToFile:atomically:

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag

Writes the contents of the receiver to the file specified by path. If
the receiver's contents are all property list objects (NSString,
NSData, NSArray, or NSDictionary objects), the file written by this
method can be used to initialize a new array with the class method
arrayWithContentsOfFile: or the instance method
initWithContentsOfFile:. This method recursively validates that all
the contained objects are property list objects before writing out the
file, and returns NO if all the objects are not property list objects,
since the resultant file would not be a valid property list.

A NSNumber is not a NSString, NSData, NSArray, or NSDictionary object.

This is true.
But my documentation (which I got last December) says in </System/Library/Frameworks/Foundation.framework/Versions/C/Resources/ English.lproj/Documentation/Reference/ObjC_classic/Classes/ NSDictionary.html>:

"If the receiver's contents are all property list objects (NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary objects), the file written by this method can be used to initialize a new dictionary with the class method dictionaryWithContentsOfFile: or the instance method initWithContentsOfFile:. "

And while the docs mention (as you did quote) that writeToFile will write only things it can read in again, this limitation is not mentioned for writeToURL.
But neither works with a NSNumber key.

Gerriet.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: write dictionary to file
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: write dictionary to file
  • Next by Date: Re: Using a framework
  • Previous by thread: Re: write dictionary to file
  • Next by thread: Re: write dictionary to file
  • Index(es):
    • Date
    • Thread