iOS Developer Library

Developer

Foundation Framework Reference NSPropertyListSerialization Class Reference

Options
Deployment Target:

On This Page
Language:

NSPropertyListSerialization

The NSPropertyListSerialization class provides methods that convert property list objects to and from several serialized formats. Property list objects include NSData, NSString, NSArray, NSDictionary, NSDate, and NSNumber objects.

Property list objects are toll-free bridged with their respective Core Foundation types (CFData, CFString, and so on). See Toll-Free Bridging for more information on toll-free bridging.

  • Returns an NSData object containing a given property list in a specified format.

    Declaration

    Swift

    class func dataWithPropertyList(_ plist: AnyObject, format format: NSPropertyListFormat, options opt: NSPropertyListWriteOptions) throws -> NSData

    Objective-C

    + (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(out NSError * _Nullable *)error

    Parameters

    plist

    A property list object. Passing nil for this value will cause an exception to be raised.

    format

    A property list format. For possible values, see NSPropertyListFormat.

    opt

    The opt parameter is currently unused. No options should be specified.

    error

    If the method does not complete successfully, upon return contains an NSError object that describes the problem.

    Return Value

    An NSData object containing plist in the format specified by format.

    Discussion

    Availability

    Available in iOS 4.0 and later.

  • Writes the specified property list to the specified stream.

    Declaration

    Swift

    class func writePropertyList(_ plist: AnyObject, toStream stream: NSOutputStream, format format: NSPropertyListFormat, options opt: NSPropertyListWriteOptions, error error: NSErrorPointer) -> Int

    Objective-C

    + (NSInteger)writePropertyList:(id)plist toStream:(NSOutputStream *)stream format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(out NSError * _Nullable *)error

    Parameters

    plist

    A property list object. Passing nil for this value will cause an exception to be raised.

    stream

    An NSStream object. The stream should be open and configured for reading.

    format

    A property list format. For possible values, see NSPropertyListFormat.

    opt

    The opt parameter is currently unused. No options should be specified.

    error

    If the method does not complete successfully, upon return contains an NSError object that describes the problem.

    Return Value

    Returns the number of bytes written to the stream. If the value is 0 an error occurred.

    Availability

    Available in iOS 4.0 and later.

Data Types

  • These constants specify mutability options in property lists.

    Declaration

    Swift

    struct NSPropertyListMutabilityOptions : OptionSetType { init(rawValue rawValue: UInt) static var Immutable: NSPropertyListMutabilityOptions { get } static var MutableContainers: NSPropertyListMutabilityOptions { get } static var MutableContainersAndLeaves: NSPropertyListMutabilityOptions { get } }

    Objective-C

    enum { NSPropertyListImmutable = kCFPropertyListImmutable, NSPropertyListMutableContainers = kCFPropertyListMutableContainers, NSPropertyListMutableContainersAndLeaves = kCFPropertyListMutableContainersAndLeaves }; typedef NSUInteger NSPropertyListMutabilityOptions;

    Constants

    • Immutable

      NSPropertyListImmutable

      Causes the returned property list to contain immutable objects.

      Available in iOS 2.0 and later.

    • MutableContainers

      NSPropertyListMutableContainers

      Causes the returned property list to have mutable containers but immutable leaves.

      Available in iOS 2.0 and later.

    • MutableContainersAndLeaves

      NSPropertyListMutableContainersAndLeaves

      Causes the returned property list to have mutable containers and leaves.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • These constants are used to specify a property list serialization format.

    Declaration

    Swift

    enum NSPropertyListFormat : UInt { case OpenStepFormat case XMLFormat_v1_0 case BinaryFormat_v1_0 }

    Objective-C

    enum { NSPropertyListOpenStepFormat = kCFPropertyListOpenStepFormat, NSPropertyListXMLFormat_v1_0 = kCFPropertyListXMLFormat_v1_0, NSPropertyListBinaryFormat_v1_0 = kCFPropertyListBinaryFormat_v1_0 }; NSPropertyListFormat; typedef NSUInteger NSPropertyListFormat;

    Constants

    • OpenStepFormat

      NSPropertyListOpenStepFormat

      Specifies the ASCII property list format inherited from the OpenStep APIs.

      Available in iOS 2.0 and later.

    • XMLFormat_v1_0

      NSPropertyListXMLFormat_v1_0

      Specifies the XML property list format.

      Available in iOS 2.0 and later.

    • BinaryFormat_v1_0

      NSPropertyListBinaryFormat_v1_0

      Specifies the binary property list format.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.