Derived from | |
Framework | CoreFoundation/CoreFoundation.h |
Declared in | CFBase.h CFPropertyList.h |
Companion guides |
CFPropertyList provides functions that convert property list objects to and from several serialized formats such as XML. The CFPropertyListRef
type that denotes CFPropertyList objects is an abstract type for property list objects. Depending on the contents of the XML data used to create the property list, CFPropertyListRef
can be any of the property list objects: CFData, CFString, CFArray, CFDictionary, CFDate, CFBoolean, and CFNumber. Note that if you use a property list to generate XML, the keys of any dictionaries in the property list must be CFString objects.
It is important to understand that CFPropertyList provides an abstraction for all the property list types—you can think of CFPropertyList in object-oriented terms as being the superclass of CFString, CFNumber, CFDictionary, and so on. When a Core Foundation function returns a CFPropertyListRef
, it means that the value may be any of the property list types. For example, CFPreferencesCopyAppValue
returns a CFPropertyListRef
. This means that the value returned can be a CFString object, a CFNumber object, a CFDictionary object, and so on again. You can use CFGetTypeID
to determine what type of object a property list value is.
You use one of the CFPropertyListCreate...
functions to create a property list object given an existing property list object, raw XML data (as in a file), or a stream. You can also convert a property list object to XML using the CFPropertyListCreateXMLData
function. You use the CFPropertyListWriteToStream
function to write a property list to an output stream, and validate a property list object using the CFPropertyListIsValid
function. CFPropertyList properly takes care of endian issues—a property list (whether represented by a stream, XML, or a CFData object) created on a PowerPC-based Macintosh is correctly interpreted on an Intel-based Macintosh, and vice versa.
For code examples illustrating how to read and write property list files, see Property List Programming Topics for Core Foundation and in particular Saving and Restoring Property Lists.
Recursively creates a copy of a given property list.
CFPropertyListRef CFPropertyListCreateDeepCopy ( CFAllocatorRef allocator, CFPropertyListRef propertyList, CFOptionFlags mutabilityOption );
The allocator to use to allocate memory for the new property list. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The property list to copy. This may be any of the standard property list objects, for example a CFArray or a CFDictionary object.
A constant that specifies the degree of mutability of the returned property list. See Property List Mutability Options for descriptions of possible values.
A new property list that is a copy of propertyList. Ownership follows the Create Rule.
Recursively creates a copy of the given property list so nested arrays and dictionaries are copied as well as the top-most container.
CFPropertyList.h
Creates a property list using data from a stream.
CFPropertyListRef CFPropertyListCreateFromStream ( CFAllocatorRef allocator, CFReadStreamRef stream, CFIndex streamLength, CFOptionFlags mutabilityOption, CFPropertyListFormat *format, CFStringRef *errorString );
The allocator to use to allocate memory for the new property list. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The stream whose data contains the content. The stream must be opened and configured—this function simply reads bytes from the stream. The stream may contain any supported property list type (see Property List Formats).
The number of bytes to read. If 0
, this function will read to the end of the stream.
A constant that specifies the degree of mutability for the returned property list. See Property List Mutability Options for descriptions of possible values.
A constant that specifies the format of the property list. See Property List Formats for possible values.
On return, NULL
if the conversion is successful, otherwise a string that describes the nature of the error. Error messages are not localized, but may be in the future, so they are not suitable for comparison.
Pass NULL
if you do not wish to receive an error string. Ownership follows the Create Rule.
A new property list initialized with the data contained in stream. Ownership follows the Create Rule.
This function simply reads bytes from stream starting at the current location to the end, which is expected to be the end of the property list, or up to the number of bytes specified by streamLength if it is not 0
.
CFPropertyList.h
Creates a property list using the specified XML or binary property list data.
CFPropertyListRef CFPropertyListCreateFromXMLData ( CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags mutabilityOption, CFStringRef *errorString );
The allocator to use to allocate memory for the new property list. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The raw bytes to convert into a property list. The bytes may be the content of an XML file or of a binary property list (see Property List Formats).
A constant that specifies the degree of mutability for the returned property list. See Property List Mutability Options for descriptions of possible values.
On return, NULL
if the conversion is successful, otherwise a string that describes the nature of the error. Error messages are not localized, but may be in the future, so they are not currently suitable for comparison.
Pass NULL
if you do not wish to receive an error string. Ownership follows the Create Rule.
A new property list if the conversion is successful, otherwise NULL
. Ownership follows the Create Rule.
CFPropertyList.h
Creates an XML representation of the specified property list.
CFDataRef CFPropertyListCreateXMLData ( CFAllocatorRef allocator, CFPropertyListRef propertyList );
The allocator to use to allocate memory for the new data object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The property list to convert. This may be any of the standard property list objects, for example a CFArray or a CFDictionary object.
A CFData object containing the XML data. Ownership follows the Create Rule.
CFPropertyList.h
Determines if a property list is valid.
Boolean CFPropertyListIsValid ( CFPropertyListRef plist, CFPropertyListFormat format );
The property list to validate.
A constant that specifies the allowable format of plist. See Property List Formats for possible values.
true
if the object graph rooted at plist is a valid property list graph—that is, the property list contains no cycles, only contains property list objects, and all dictionary keys are strings; otherwise false
.
The debugging library version of this function prints out some useful messages.
CFPropertyList.h
Writes the bytes of a property list serialization out to a stream.
CFIndex CFPropertyListWriteToStream ( CFPropertyListRef propertyList, CFWriteStreamRef stream, CFPropertyListFormat format, CFStringRef *errorString );
The property list to write out.
The stream to write to. The stream must be opened and configured—this function simply writes bytes to the stream.
A constant that specifies the format used to write propertyList. See Property List Formats for possible values.
On return, NULL
if the conversion is successful, otherwise a string that describes the nature of the errors. Error messages are not localized, but may be in the future, so they are not currently suitable for comparison.
Pass NULL
if you do not wish to receive an error string. Ownership follows the Create Rule.
The number of bytes written, or 0
if an error occurred. If 0
is returned, errorString will contain an error message.
This function leaves the stream open after reading the content. When reading a property list, this function expects the reading stream to end wherever the writing ended, so that the end of the property list data can be identified.
CFPropertyList.h
A reference to a CFPropertyList object.
typedef CFTypeRef CFPropertyListRef;
This is an abstract type for property list objects. The return value of the CFPropertyListCreateFromXMLData
function depends on the contents of the given XML data. CFPropertyListRef
can be a reference to any of the property list objects: CFData, CFString, CFArray, CFDictionary, CFDate, CFBoolean, and CFNumber.
CFBase.h
Specifies the format of a property list.
enum CFPropertyListFormat { kCFPropertyListOpenStepFormat = 1, kCFPropertyListXMLFormat_v1_0 = 100, kCFPropertyListBinaryFormat_v1_0 = 200 }; typedef enum CFPropertyListFormat CFPropertyListFormat;
kCFPropertyListOpenStepFormat
OpenStep format (use of this format is discouraged).
Available in Mac OS X v10.2 and later.
Declared in CFPropertyList.h
.
kCFPropertyListXMLFormat_v1_0
XML format version 1.0.
Available in Mac OS X v10.2 and later.
Declared in CFPropertyList.h
.
kCFPropertyListBinaryFormat_v1_0
Binary format version 1.0.
Available in Mac OS X v10.2 and later.
Declared in CFPropertyList.h
.
Option flags that determine the degree of mutability of newly created property lists.
enum CFPropertyListMutabilityOptions { kCFPropertyListImmutable = 0, kCFPropertyListMutableContainers = 1, kCFPropertyListMutableContainersAndLeaves = 2 }; typedef enum CFPropertyListMutabilityOptions CFPropertyListMutabilityOptions;
kCFPropertyListImmutable
Specifies that the property list should be immutable.
Available in Mac OS X v10.0 and later.
Declared in CFPropertyList.h
.
kCFPropertyListMutableContainers
Specifies that the property list should have mutable containers but immutable leaves.
Available in Mac OS X v10.0 and later.
Declared in CFPropertyList.h
.
kCFPropertyListMutableContainersAndLeaves
Specifies that the property list should have mutable containers and mutable leaves.
Available in Mac OS X v10.0 and later.
Declared in CFPropertyList.h
.
© 2003, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-02-07)