Re: NSString propertyList crash
Re: NSString propertyList crash
- Subject: Re: NSString propertyList crash
- From: Andy Lee <email@hidden>
- Date: Sun, 19 Mar 2006 23:07:30 -0500
On Mar 19, 2006, at 10:20 PM, Andy Lee wrote:
I suspect the solution is to use whatever CoreFoundation function
is the inverse of CFPropertyListCreateFromXMLData(), because the
Objective-C APIs for doing what you want are broken right now.
I take that back.  As others have suggested in this and your previous
thread, NSPropertyListSerialization is your friend:
    NSString *dirPath = [[myTextField2 stringValue]
stringByExpandingTildeInPath];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:
dirPath];
    NSLog(@"dict: %@", dict);
    NSString *err = nil;
    NSData *dictData =
        [NSPropertyListSerialization
            dataFromPropertyList:dict
            format:NSPropertyListXMLFormat_v1_0
            errorDescription:&err];
    NSString *dictXML =
        [[[NSString alloc]
            initWithBytes:(const void *)[dictData bytes]
            length:[dictData length]
            encoding:NSUTF8StringEncoding] autorelease];
    NSLog(@"dictXML: %@", dictXML);
You now have an NSString containing XML, and an NSData that you can
use to reconstitute the original dictionary using
NSPropertyListSerialization.
--Andy
_______________________________________________
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