iOS Developer Library

Developer

Foundation Framework Reference NSPropertyListSerialization Class Reference

Options
Deployment Target:

On This Page
Language:

NSPropertyListSerialization

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later.

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. These objects are toll-free bridged with their respective Core Foundation types (CFData, CFString, and so on). For more about toll-free bridging, see Interchangeable Data Types.

  • 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, error error: NSErrorPointer) -> NSData?

    Objective-C

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

    Parameters

    plist

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

    format

    A property list format. Possible values for format are described in NSPropertyListFormat.

    opt

    The opt parameter is currently unused and should be set to 0.

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    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 **)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. Possible values for format are described in NSPropertyListFormat.

    opt

    The opt parameter is currently unused and should be set to 0.

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Creates and returns a property list from the specified data.

    Declaration

    Swift

    class func propertyListWithData(_ data: NSData, options opt: NSPropertyListReadOptions, format format: UnsafeMutablePointer<NSPropertyListFormat>, error error: NSErrorPointer) -> AnyObject?

    Objective-C

    + (id)propertyListWithData:(NSData *)data options:(NSPropertyListReadOptions)opt format:(NSPropertyListFormat *)format error:(out NSError **)error

    Parameters

    data

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

    opt

    The options can be any of those listed in NSPropertyListMutabilityOptions.

    format

    Upon return, contains the format that the property list was stored in. Pass NULL if you do not need to know the format.

    error

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

    Return Value

    A property list object corresponding to the representation in data. If data is not in a supported format, returns nil.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Creates and returns a property list by reading from the specified stream.

    Declaration

    Swift

    class func propertyListWithStream(_ stream: NSInputStream, options opt: NSPropertyListReadOptions, format format: UnsafeMutablePointer<NSPropertyListFormat>, error error: NSErrorPointer) -> AnyObject?

    Objective-C

    + (id)propertyListWithStream:(NSInputStream *)stream options:(NSPropertyListReadOptions)opt format:(NSPropertyListFormat *)format error:(out NSError **)error

    Parameters

    stream

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

    opt

    Set to 0—read options are not implemented.

    format

    Upon return, contains the format that the property list was stored in. Pass NULL if you do not need to know the format.

    error

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

    Return Value

    A property list object corresponding to the representation in data. If data is not in a supported format, returns nil.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given property list is valid for a given format.

    Declaration

    Swift

    class func propertyList(_ plist: AnyObject, isValidForFormat format: NSPropertyListFormat) -> Bool

    Objective-C

    + (BOOL)propertyList:(id)plist isValidForFormat:(NSPropertyListFormat)format

    Parameters

    plist

    A property list object.

    format

    A property list format. Possible values for format are listed in NSPropertyListFormat.

    Return Value

    YEStrue if plist is a valid property list in format format, otherwise NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

Data Types

  • These constants specify mutability options in property lists.

    Declaration

    Swift

    struct NSPropertyListMutabilityOptions : RawOptionSetType { init(_ rawValue: UInt) 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.