RE: plist help?
RE: plist help?
- Subject: RE: plist help?
- From: Lance Drake <email@hidden>
- Date: Sat, 20 Sep 2003 11:36:27 -0600
Hi Daniel,
That plist stuff should not be a messy problem. I am SURE there
are others who could provide an even more simplified approach, but I
have found this to work...
First, put your info into a dictionary and send it to a routine like
this...
- (OSErr) WriteInfoToFile:(CFPropertyListRef)theXMLInfo
forFile:(NSString*)filename
{
OSErr theErr = noErr;
CFDataRef theXMLData = CFPropertyListCreateXMLData(NULL, theXMLInfo);
CFIndex theXMLSize = CFDataGetLength(theXMLData);
if(0 < theXMLSize)
{
FILE *theFile = NULL;
char* cstr = (char*)[filename cString];
theErr = <FILE_PerformOpen>(&theFile, cstr, kForWrite);
if((noErr == theErr) && (0 != theFile))
{
<FILE_PerformWrite>(theFile, (UInt8*)CFDataGetBytePtr(theXMLData),
theXMLSize);
<FILE_PerformClose>(theFile);
}
}
else
{
theErr = kWhateverErrorYouWantToReturn;
}
return(theErr);
}
// ---------------------------------------------------------
Later, you could read it in...
CFPropertyListRef localPlist;
CFDataRef cfData;
UInt8 *buffer;
CFIndex fileSize;
OPEN FILE
LEARN FILE SIZE
CREATE BUFFER OF FILE SIZE
READ INTO BUFFER
CLOSE FILE
cfData = CFDataCreate(NULL, buffer, fileSize);
if(NULL != cfData)
localPlist = CFPropertyListCreateFromXMLData(NULL, cfData,
kCFPropertyListImmutable, nil);
Then calls like "keyCFString =
(CFStringRef)CFDictionaryGetValue(localPlist, valueString);"
would return whatever particular item it was you were looking for.
// -----------------------------------------------------------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.