---
title: "writeBookmarkData(_:to:options:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsurl/writebookmarkdata(_:to:options:)"
---

# writeBookmarkData(_:to:options:)

Creates an alias file on disk at a specified location with specified bookmark data.

## Declaration

```swift
class func writeBookmarkData(_ bookmarkData: Data, to bookmarkFileURL: URL, options: NSURL.BookmarkFileCreationOptions) throws
```

## Parameters

- `bookmarkData`: The bookmark data containing information for the alias file.
- `bookmarkFileURL`: The desired location of the alias file.
- `options`: Options taken into account when creating the alias file.

## Discussion

Discussion This method will produce an error if bookmarkData was not created with the NSURLBookmarkCreationSuitableForBookmarkFile option. If bookmarkFileURL points to a directory, the alias file will be created in that directory with its name derived from the information in bookmarkData. If bookmarkFileURL points to a file, the alias file will be created with the location and name indicated by bookmarkFileURL, and its extension will be changed to .alias if it is not already. 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

### Working with Bookmark Data

- [bookmarkData(withContentsOf:)](foundation/nsurl/bookmarkdata(withcontentsof:).md)
- [bookmarkData(options:includingResourceValuesForKeys:relativeTo:)](foundation/nsurl/bookmarkdata(options:includingresourcevaluesforkeys:relativeto:).md)
- [resourceValues(forKeys:fromBookmarkData:)](foundation/nsurl/resourcevalues(forkeys:frombookmarkdata:).md)
- [startAccessingSecurityScopedResource()](foundation/nsurl/startaccessingsecurityscopedresource().md)
- [stopAccessingSecurityScopedResource()](foundation/nsurl/stopaccessingsecurityscopedresource().md)
- [NSURL.BookmarkFileCreationOptions](foundation/nsurl/bookmarkfilecreationoptions.md)
- [NSURL.BookmarkCreationOptions](foundation/nsurl/bookmarkcreationoptions.md)
- [NSURL.BookmarkResolutionOptions](foundation/nsurl/bookmarkresolutionoptions.md)
