Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Saving CFArray/CFDict/CFData to disk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving CFArray/CFDict/CFData to disk




Thanks for the suggestions George. I'd already checked those (sorry, I should have mentioned it).


I've now created a simplified example project to show the problem: <http://homepage.ntlworld.com/bernie.w/ReadWriteCFArrayTest.zip> (20K). After doing a File>Save As, the example creates an array with just one CFData element which is created from a struct containing just one CFString. Once the XML data is created and written to disk, opening the file in Property List Editor shows the data element as empty (<>).

The array create and write functions:

//--------------------
typedef struct DBData
{
	CFStringRef	string;
} DBData;


CFMutableArrayRef CreateArray( void )
{
CFMutableArrayRef array = 0;
CFMutableDataRef data;
DBData cellData;

array = CFArrayCreateMutable( NULL, 0, &kCFTypeArrayCallBacks );
if ( array )
{
data = CFDataCreateMutable( NULL, 0 );
if ( data )
{
cellData.string = CFSTR( "MyData" );
CFDataReplaceBytes( data, CFRangeMake( 0, sizeof(DBData) ), (UInt8*)&cellData, sizeof(DBData) );
CFArrayAppendValue( array, data );
CFRelease( data );
}
}
return array;
}



Boolean WriteArray( CFMutableArrayRef array, CFURLRef url )
{
Boolean result = false;

CFDataRef data = CFPropertyListCreateXMLData( NULL, array );
if ( data )
{
result = CFURLWriteDataAndPropertiesToResource( url, data, NULL, NULL );
CFRelease( data );
}
return result;
}
//--------------------


Thank you.

Bernie






On 23 May 2007, at 21:06, George Warner wrote:

On Wed, 23 May 2007 14:43:10 +0100, Bernie <email@hidden>
wrote:



I have a CFMutableArray where each element is a CFMutableDictionary

Each dict has three key/value pairs (all keys are CFStrings):
 Key    Value
 "Container"  CFBooleanRef
 "Parent"   CFNumberRef
 "Data"   CFMutableDataRef

I'm saving the array to disk with:
 CFDataRef data = CFPropertyListCreateXMLData( NULL, array );
 Boolean ok = CFURLWriteDataAndPropertiesToResource( url, data, NULL,
NULL );

Unfortunately, the "Data" value doesn't appear to get written to disk.

Any ideas what I may be doing wrong?

I assume your code is based on this Q&A: <http://developer.apple.com/qa/qa2001/qa1208.html>?

Can you verify the dictionary is good? CFShow it? Is data NULL (meaning that
CFPropertyListCreateXMLData failed)? Is the url valid? The last parameter to
CFURLWriteDataAndPropertiesToResource is an address where to store an error
code. What's it returning?






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >re: Saving CFArray/CFDict/CFData to disk (From: George Warner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.