---
title: "bookmarkData(withContentsOf:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsurl/bookmarkdata(withcontentsof:)"
---

# bookmarkData(withContentsOf:)

Initializes and returns bookmark data derived from an alias file pointed to by a specified URL.

## Declaration

```swift
class func bookmarkData(withContentsOf bookmarkFileURL: URL) throws -> Data
```

## Parameters

- `bookmarkFileURL`: The URL that points to a file containing bookmark data.

## Return Value

Return Value The bookmark data for the alias file.

## Discussion

Discussion This method doesn’t check to see if bookmarkFileURL points to an alias file. This allows this method to work with any file containing bookmark data. If bookmarkFileURL refers to a file which does not contain bookmark data or to a non-file object, such as a directory or symbolic link, this method returns nil produces an error. This method returns nil if bookmark data cannot be created. 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(options:includingResourceValuesForKeys:relativeTo:)](foundation/nsurl/bookmarkdata(options:includingresourcevaluesforkeys:relativeto:).md)
- [resourceValues(forKeys:fromBookmarkData:)](foundation/nsurl/resourcevalues(forkeys:frombookmarkdata:).md)
- [writeBookmarkData(_:to:options:)](foundation/nsurl/writebookmarkdata(_:to:options:).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)
