Re: writeToFile:atomically ... again
Re: writeToFile:atomically ... again
- Subject: Re: writeToFile:atomically ... again
- From: "stephen joseph butler" <email@hidden>
- Date: Sun, 10 Jun 2007 13:32:58 -0500
On 6/10/07, Nima Talebi <email@hidden> wrote:
Problem Method: [NSDictionary writeToFile:atomically:] fails everytime, and
I don't know why.
Test Case: I've pasted the original email here...
http://dark-code.bulix.org/f0dcgo-44875?raw
Results/Problem:
As you can see, the writeToFile:atomically works perfectly fine for NSArray
of NSNumbers and NSStrings, however the resultant NSDictionary fails.
When serializing a dictionary can only contain strings for keys. I
swear that the docs say this somewhere, but I can't find it at the
moment. Anyway, this code works for me in the example where I use
strings for keys:
<https://netfiles.uiuc.edu/sbutler1/www/atomic-test.m>. You say you
tested strings for keys, but I don't know why that's failing for you.
There were a couple things I noticed about your code, however:
NSLog([someKeys description]); //An NSArray of NSNumbers
This is very bad practice and opens you up for printf vulnerabilities.
The way you should do it is this:
NSLog( "@%", someKeys );
or even better:
NSLog( @"someKeys = %@", someKeys );
entries = (NSDictionary*)
[NSDictionary
dictionaryWithObjects:(NSArray*)someValues
forKeys:(NSArray *)someKeys];
I don't understand why you are casting here.
+dictionaryWithObjects:forKeys: returns an NSDictionary*. Also, if
someValues and someKeys aren't NSArray's then you shouldn't be passing
them as parameters.
_______________________________________________
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