---
title: "data(fromPropertyList:format:options:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/propertylistserialization/data(frompropertylist:format:options:)"
---

# data(fromPropertyList:format:options:)

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

## Declaration

```swift
class func data(fromPropertyList plist: Any, format: PropertyListSerialization.PropertyListFormat, options opt: PropertyListSerialization.WriteOptions) throws -> Data
```

## Parameters

- `plist`: A property list object.
- `format`: A property list format. For possible values, see doc://com.apple.foundation/documentation/Foundation/PropertyListSerialization/PropertyListFormat.
- `opt`: The opt parameter is currently unused. No options should be specified.

## Return Value

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

## Discussion

Discussion note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Related Documentation

- [Archives and Serializations Programming Guide](apple-archive/documentation/Cocoa/Conceptual/Archiving.md)
- [Property List Programming Guide](apple-archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction.md)

### Serializing a Property List

- [writePropertyList(_:to:format:options:error:)](foundation/propertylistserialization/writepropertylist(_:to:format:options:error:).md)
- [PropertyListSerialization.WriteOptions](foundation/propertylistserialization/writeoptions.md)
