[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
XML-style plists with the [NSDictionary writeToFile:]
From: |
Мелешкин Валерий |
Subject: |
XML-style plists with the [NSDictionary writeToFile:] |
Date: |
Tue, 28 Apr 2009 11:57:14 +0400 |
I want to write plists in XML-style with the [NSDictionary
writeToFile...]. After some googling I wrote the test app:
#include <Foundation/Foundation.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSLog( @"%i, %i\n",
[[NSUserDefaults standardUserDefaults]
boolForKey: @"GSMacOSXCompatible"],
[[NSUserDefaults standardUserDefaults]
boolForKey:
@"NSWriteOldStylePropertyLists"] );
[[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:
@"GSMacOSXCompatible"];
[[NSUserDefaults standardUserDefaults] setObject: @"NO" forKey:
@"NSWriteOldStylePropertyLists"];
NSLog( @"%i, %i\n",
[[NSUserDefaults standardUserDefaults]
boolForKey: @"GSMacOSXCompatible"],
[[NSUserDefaults standardUserDefaults]
boolForKey:
@"NSWriteOldStylePropertyLists"] );
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:
@"opts.plist"];
NSLog(@"%@\n", dict);
[dict writeToFile: @"./opts.out.plist" atomically: YES];
[pool release];
return 0;
}
The contents of "opts.plist" are:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Name</key>
<string>John Doe</string>
<key>Phones</key>
<array>
<string>408-974-0000</string>
<string>503-333-5555</string>
</array>
</dict>
</plist>
To my surprise, just after execution of app "opts.out.plist" looks like this:
{
Name = "John Doe";
Phones = (
"408-974-0000",
"503-333-5555"
);
}
Where a mistake is?
- XML-style plists with the [NSDictionary writeToFile:],
Мелешкин Валерий <=