Re: plists, core foundation and cocoa
Re: plists, core foundation and cocoa
- Subject: Re: plists, core foundation and cocoa
- From: Clyde McQueen <email@hidden>
- Date: Sun, 3 Jun 2001 14:34:17 -0700
Thanks to all for snippets, etc.
I can't believe I missed seeing the "propertyList" method in NSString.
Not quite the same as XML, but close enough for my needs.
/Clyde
On Saturday, June 2, 2001, at 03:05 AM, Izidor Jerebic wrote:
On Saturday, June 2, 2001, at 07:15 AM, Deirdre Saoirse Moen wrote:
Dumb newbie questions:
I'd like to read a XML file in plist form and turn it into Cocoa
objects,
and vice-versa. Is that what NSSerializer does? If not, how can I do
this?
Along those lines, are the Cocoa "property list" objects related to
the CF property list objects? Is Cocoa Foundation built on top of
Core Foundation?
OK, OK, I promised to post my example at WWDC and I hadn't. I've been
busy. :)
See my pListArchiving protocol and the example to show how to
read/write from an XML file. I didn't implement all data types I'd
intended and I meant to clean up the example a bit, but it does answer
your question.
http://deirdre.net/SillyFile.tar.gz
Use it however you like except to tar and feather. ;)
If you want Objective-C and Foundation (the above example is using
CoreFoundation - useful in pure C) you can proceed like code below. My
silly (:-) code uses hardcoded constants for everything, but it shows
the principle. The example creates a file /tmp/a which is a property
list in XML format, and then reads it into immutable dictionary. No
error checking etc... But it does compile and work on my machine :-)
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *d ;
NSDictionary *d2 ;
// create
d = [NSMutableDictionary dictionary] ;
[d setObject:@"stringValue" forKey:@"key string"] ;
[d setObject:[NSNumber numberWithInt:10] forKey:@"key int"] ;
[d writeToFile:@"/tmp/a" atomically:YES] ;
// read
d2 = [[NSString stringWithContentsOfFile:@"/tmp/a"] propertyList] ;
NSLog( @"d2 = %@", d2 ) ;
[pool release];
return 0;
}
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev