Skip to content

Instantly share code, notes, and snippets.

@bluebanboom
Created December 8, 2012 06:03
Show Gist options
  • Save bluebanboom/4238875 to your computer and use it in GitHub Desktop.
Save bluebanboom/4238875 to your computer and use it in GitHub Desktop.
Read Plist.
#import <Foundation/Foundation.h>
CFPropertyListRef CreateMyPropertyListFromFile(CFURLRef fileURL)
{
CFPropertyListRef propertyList;
CFStringRef errorString;
CFDataRef resourceData;
Boolean status;
SInt32 errorCode;
// Read the XML file.
status = CFURLCreateDataAndPropertiesFromResource(
kCFAllocatorDefault,
fileURL,
&resourceData, // place to put file data
NULL,
NULL,
&errorCode);
// Reconstitute the dictionary using the XML data.
propertyList = CFPropertyListCreateFromXMLData( kCFAllocatorDefault,
resourceData,
kCFPropertyListImmutable,
&errorString);
CFRelease( resourceData );
return propertyList;
}
int main()
{
NSLog(@"Test");
CFPropertyListRef propertyList;
CFURLRef fileURL;
// Construct a complex dictionary object;
// Create a URL that specifies the file we will create to
// hold the XML data.
fileURL = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
CFSTR("iTunesMetadata.plist"), // file path name
kCFURLPOSIXPathStyle, // interpret as POSIX path
false ); // is it a directory?
propertyList = CreateMyPropertyListFromFile(fileURL);
CFRelease(propertyList);
CFRelease(fileURL);
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:@"iTunesMetadata.plist"];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
NSLog(@"%@", [temp objectForKey:@"itemName"]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment