<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURL",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURL"
  },
  "title" : "NSURL"
}
-->

# NSURL

An object that represents the location of a resource, such as an item on a remote server or the path to a local file.

```
class NSURL
```

## Overview

In Swift, this object bridges to [`URL`](/documentation/Foundation/URL); use [`NSURL`](/documentation/Foundation/NSURL) when you need reference semantics or other Foundation-specific behavior.

You can use URL objects to construct URLs and access their parts. For URLs that represent local files, you can also manipulate properties of those files directly, such as changing the file’s last modification date. Finally, you can pass URL objects to other APIs to retrieve the contents of those URLs. For example, you can use the [`URLSession`](/documentation/Foundation/URLSession), [`NSURLConnection`](/documentation/Foundation/NSURLConnection), and [`NSURLDownload`](/documentation/Foundation/NSURLDownload) classes to access the contents of remote resources, as described in [URL Loading System](/documentation/Foundation/url-loading-system).

URL objects are the preferred way to refer to local files. Most objects that read data from or write data to a file have methods that accept an [`NSURL`](/documentation/Foundation/NSURL) object instead of a pathname as the file reference. For example, you can get the contents of a local file URL as an `NSString` object using the `NSString/init(contentsOfURL:encoding:)-715fw` initializer, or as an `NSData` object using the `NSData/init(contentsOfURL:options:)-5abi3` initializer.

You can also use URLs for interapplication communication. In macOS, the <doc://com.apple.documentation/documentation/AppKit/NSWorkspace> class provides the <doc://com.apple.documentation/documentation/AppKit/NSWorkspace/open(_:)> method to open a location specified by a URL. Similarly, in iOS, the <doc://com.apple.documentation/documentation/UIKit/UIApplication> class provides the <doc://com.apple.documentation/documentation/UIKit/UIApplication/open(_:options:completionHandler:)> method.

Additionally, you can use URLs when working with pasteboards, as described in NSURL Additions Reference (part of the AppKit framework).

The [`NSURL`](/documentation/Foundation/NSURL) class is “toll-free bridged” with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFURL>. See [Toll-Free Bridging](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2) for more information on toll-free bridging.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/URL`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSURL`` class. For more information about value types, see [Classes and Structures](https://developer.apple.com/library/archive/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html#//apple_ref/doc/uid/TP40014097-CH13) in [The Swift Programming Language (Swift 4.1)](https://developer.apple.com/library/archive/documentation/Swift/Conceptual/Swift_Programming_Language/index.html#//apple_ref/doc/uid/TP40014097) and [Working with Cocoa Frameworks](https://developer.apple.com/library/archive/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html#//apple_ref/doc/uid/TP40014216-CH6) in [Using Swift with Cocoa and Objective-C (Swift 4.1)](https://developer.apple.com/library/archive/documentation/Swift/Conceptual/BuildingCocoaApps/index.html#//apple_ref/doc/uid/TP40014216).

### Structure of a URL

An [`NSURL`](/documentation/Foundation/NSURL) object is composed of two parts—a potentially `nil` base URL and a string that is resolved relative to the base URL. An [`NSURL`](/documentation/Foundation/NSURL) object is considered absolute if its string part is fully resolved without a base; all other URLs are considered relative.

For example, when constructing an `NSURL` object, you might specify `file:///path/to/user/` as the base URL and `folder/file.html` as the string part, as follows:

```objc
NSURL *baseURL = [NSURL fileURLWithPath:@"file:///path/to/user/"];
NSURL *URL = [NSURL URLWithString:@"folder/file.html" relativeToURL:baseURL];
NSLog(@"absoluteURL = %@", [URL absoluteURL]);
```

When fully resolved, the absolute URL is `file:///path/to/user/folder/file.html`.

A URL can be also be divided into pieces based on its structure. For example, the URL `https://johnny:p4ssw0rd@www.example.com:443/script.ext;param=value?query=value#ref` contains the following URL components:

|Component                                                                    |Value                |
|-----------------------------------------------------------------------------|---------------------|
|``doc://com.apple.foundation/documentation/Foundation/NSURL/scheme``         |`https`              |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/user``           |`johnny`             |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/password``       |`p4ssw0rd`           |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/host``           |`www.example.com`    |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/port``           |`443`                |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/path``           |`/script.ext`        |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/pathExtension``  |`ext`                |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/pathComponents`` |`["/", "script.ext"]`|
|``doc://com.apple.foundation/documentation/Foundation/NSURL/parameterString``|`param=value`        |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/query``          |`query=value`        |
|``doc://com.apple.foundation/documentation/Foundation/NSURL/fragment``       |`ref`                |

The [`NSURL`](/documentation/Foundation/NSURL) class provides properties that let you examine each of these components.

> Important:
> For apps linked on or after iOS 17 and aligned OS versions, ``doc://com.apple.foundation/documentation/Foundation/NSURL`` parsing has updated from the obsolete RFC 1738/1808 parsing to the same [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt) parsing as ``doc://com.apple.foundation/documentation/Foundation/NSURLComponents``. This unifies the parsing behaviors of the `NSURL` and `NSURLComponents` APIs. Now, `NSURL` automatically percent- and IDNA-encodes invalid characters to help create a valid URL.
> 
> To check if a `URLString` is strictly valid according to the RFC, use the new `[NSURL URLWithString:URLString encodingInvalidCharacters:NO]` method. This method leaves all characters as they are and returns `nil` if `URLString` is explicitly invalid.

For apps linked before iOS 17, the [`NSURL`](/documentation/Foundation/NSURL) class parses URLs according to [RFC 1808](https://tools.ietf.org/html/rfc1808), [RFC 1738](https://tools.ietf.org/html/rfc1738), and [RFC 2732](https://tools.ietf.org/html/rfc2732).

### Bookmarks and Security Scope

Starting with OS X v10.6 and iOS 4.0, the [`NSURL`](/documentation/Foundation/NSURL) class provides a facility for creating and using bookmark objects. A **bookmark** provides a persistent reference to a file-system resource. When you resolve a bookmark, you obtain a URL to the resource’s current location. A bookmark’s association with a file-system resource (typically a file or folder) usually continues to work if the user moves or renames the resource, or if the user relaunches your app or restarts the system.

For a general introduction to using bookmarks, read [Locating Files Using Bookmarks](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10) in [File System Programming Guide](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672).

In a macOS app that adopts App Sandbox, you can use **security-scoped bookmarks** to gain access to file-system resources outside your app’s sandbox. These bookmarks preserve the user’s intent to give your app access to a resource across app launches. For details on how this works, including information on the entitlements you need in your Xcode project, read [Security-Scoped Bookmarks and Persistent Resource Access](https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW16) in [App Sandbox Design Guide](https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html#//apple_ref/doc/uid/TP40011183). The methods for using security-scoped bookmarks are described in this document in Working with Bookmark Data.

When you resolve a security-scoped bookmark, you get a security-scoped URL.

### Security-Scoped URLs

Security-scoped URLs provide access to resources outside an app’s sandbox. In macOS, you get access to security-scoped URLs when you resolve a security-scoped bookmark. In iOS, apps that *open* or *move* documents using a <doc://com.apple.documentation/documentation/UIKit/UIDocumentPickerViewController> also receive security-scoped URLs.

To gain access to a security-scoped URL, you must call the [`startAccessingSecurityScopedResource()`](/documentation/Foundation/NSURL/startAccessingSecurityScopedResource()) method (or its Core Foundation equivalent, the <doc://com.apple.documentation/documentation/CoreFoundation/CFURLStartAccessingSecurityScopedResource(_:)> function). For iOS apps, if you use a <doc://com.apple.documentation/documentation/UIKit/UIDocument> to access the URL, it automatically manages the security-scoped URL for you.

If `startAccessingSecurityScopedResource` (or `CFUrLStartAccessingSecurityScopedResource`) returns <doc://com.apple.documentation/documentation/Swift/true>, you must relinquish your access by calling the [`stopAccessingSecurityScopedResource()`](/documentation/Foundation/NSURL/stopAccessingSecurityScopedResource()) method (or its Core Foundation equivalent, the <doc://com.apple.documentation/documentation/CoreFoundation/CFURLStopAccessingSecurityScopedResource(_:)> function). You should relinquish your access as soon as you have finished using the file. After you call these methods, you immediately lose access to the resource in question.

> Warning:
> If you fail to relinquish your access when you no longer need a file-system resource, your app leaks kernel resources. If sufficient kernel resources are leaked, your app loses its ability to add file-system locations to its sandbox, using Powerbox, security-scoped bookmarks, or similar APIs, until relaunched.

#### Security-Scoped URLs and String Paths

In a macOS app, when you copy a security-scoped URL, the copy has the security scope of the original. You gain access to the file-system resource (that the URL points to) just as you would with the original URL: by calling the [`startAccessingSecurityScopedResource()`](/documentation/Foundation/NSURL/startAccessingSecurityScopedResource()) method (or its Core Foundation equivalent).

If you need a security-scoped URL’s path as a string value (as provided by the [`path`](/documentation/Foundation/NSURL/path) method), such as to provide to an API that requires a string value, obtain the path from the URL as needed. Note, however, that a string-based path obtained from a security-scoped URL *does not* have security scope and you cannot use that string to obtain access to a security-scoped resource.

### iCloud Document Thumbnails

With OS X v10.10 and iOS 8.0, the NSURL class includes the ability to get and set document thumbnails as a resource property for iCloud documents. You can get a dictionary of <doc://com.apple.documentation/documentation/AppKit/NSImage> objects in macOS or <doc://com.apple.documentation/documentation/UIKit/UIImage> objects in iOS using the [`getResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/getResourceValue(_:forKey:)) or [`getPromisedItemResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/getPromisedItemResourceValue(_:forKey:)) methods.

```swift
let URL = self.URLForDocument()
var thumbnails: AnyObject?
 
do {
    try URL.getResourceValue(&thumbnails, forKey: NSURLThumbnailDictionaryKey)
    if let thumbnails = thumbnails as? [NSString: NSImage] {
        let image = thumbnails[NSThumbnail1024x1024SizeKey]
    }
} catch {
    // handle the error
}
```

In macOS, you can set a dictionary of thumbnails using the [`setResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/setResourceValue(_:forKey:)) method. You can also get or set all the thumbnails as an `NSImage` object with multiple representations by using the [`thumbnailKey`](/documentation/Foundation/URLResourceKey/thumbnailKey).

```swift
let URL = self.URLForDocument()
let thumbnail = self.createDocumentThumbnail()
 
do {
    try URL.setResourceValue([NSThumbnail1024x1024SizeKey: thumbnail], forKey: NSURLThumbnailDictionaryKey)
} catch {
    // handle the error
}
```

> Note:
> Do not set the ``doc://com.apple.foundation/documentation/Foundation/URLResourceKey/thumbnailDictionaryKey`` key directly. Modifying this key interferes with document tracking and can create duplicates of your document, as well as other possible problems.
> 
> In iOS, use a <doc://com.apple.documentation/documentation/UIKit/UIDocument> subclass to manage your file. Set the thumbnail by overriding the document’s <doc://com.apple.documentation/documentation/UIKit/UIDocument/fileAttributesToWrite(to:for:)> method and returning a dictionary that contains the proper thumbnail keys (along with any other file attributes).
> 
> In macOS, follow the instructions for creating thumbnails given in [Quick Look Programming Guide](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/Quicklook_Programming_Guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005020).

> Note:
> Although the thumbnail API is designed to support multiple image resolutions, currently it only supports 1024 x 1024 pixel thumbnails.

## Topics

### Creating a URL object

[`URLWithString:`](/documentation/Foundation/NSURL/URLWithString:)

Creates and returns an NSURL object initialized with a provided URL string.

[`init(string:)`](/documentation/Foundation/NSURL/init(string:))

Initializes an NSURL object with a provided URL string.

[`URLWithString:encodingInvalidCharacters:`](/documentation/Foundation/NSURL/URLWithString:encodingInvalidCharacters:)

Creates and returns an instance from the provided string, optionally IDNA- and percent-encoding any invalid characters.

[`init(string:encodingInvalidCharacters:)`](/documentation/Foundation/NSURL/init(string:encodingInvalidCharacters:))

Creates an instance from the provided string, optionally IDNA- and percent-encoding any invalid characters.

[`URLWithString:relativeToURL:`](/documentation/Foundation/NSURL/URLWithString:relativeToURL:)

Creates and returns an NSURL object initialized with a base URL and a relative string.

[`init(string:relativeTo:)`](/documentation/Foundation/NSURL/init(string:relativeTo:))

Initializes an NSURL object with a base URL and a relative string.

[`fileURL(withPath:isDirectory:)`](/documentation/Foundation/NSURL/fileURL(withPath:isDirectory:))

Initializes and returns a newly created NSURL object as a file URL with a specified path.

[`init(fileURLWithPath:isDirectory:)`](/documentation/Foundation/NSURL/init(fileURLWithPath:isDirectory:))

Initializes a newly created NSURL referencing the local file or directory at `path`.

[`fileURL(withPath:relativeTo:)`](/documentation/Foundation/NSURL/fileURL(withPath:relativeTo:))

Initializes and returns a newly created file NSURL referencing the local file or directory at path, relative to a base URL.

[`init(fileURLWithPath:relativeTo:)`](/documentation/Foundation/NSURL/init(fileURLWithPath:relativeTo:))

Initializes a newly created file NSURL referencing the local file or directory at path, relative to a base URL.

[`fileURL(withPath:isDirectory:relativeTo:)`](/documentation/Foundation/NSURL/fileURL(withPath:isDirectory:relativeTo:))

Initializes and returns a newly created file NSURL referencing the local file or directory at path, relative to a base URL.

[`init(fileURLWithPath:isDirectory:relativeTo:)`](/documentation/Foundation/NSURL/init(fileURLWithPath:isDirectory:relativeTo:))

Initializes a newly created file NSURL referencing the local file or directory at path, relative to a base URL.

[`fileURL(withPath:)`](/documentation/Foundation/NSURL/fileURL(withPath:))

Initializes and returns a newly created NSURL object as a file URL with a specified path.

[`init(fileURLWithPath:)`](/documentation/Foundation/NSURL/init(fileURLWithPath:))

Initializes a newly created NSURL referencing the local file or directory at `path`.

[`fileURL(withPathComponents:)`](/documentation/Foundation/NSURL/fileURL(withPathComponents:))

Initializes and returns a newly created NSURL object as a file URL with specified path components.

[`init(resolvingAliasFileAt:options:)`](/documentation/Foundation/NSURL/init(resolvingAliasFileAt:options:))

Returns a new URL made by resolving the alias file at `url`.

[`URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:`](/documentation/Foundation/NSURL/URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:)

Returns a new URL made by resolving bookmark data.

[`init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:)`](/documentation/Foundation/NSURL/init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:))

Initializes a newly created NSURL that points to a location specified by resolving bookmark data.

[`fileURL(withFileSystemRepresentation:isDirectory:relativeTo:)`](/documentation/Foundation/NSURL/fileURL(withFileSystemRepresentation:isDirectory:relativeTo:))

Returns a new URL object initialized with a C string representing a local file system path.

[`getFileSystemRepresentation(_:maxLength:)`](/documentation/Foundation/NSURL/getFileSystemRepresentation(_:maxLength:))

Fills the provided buffer with a C string representing a local file system path.

[`init(fileURLWithFileSystemRepresentation:isDirectory:relativeTo:)`](/documentation/Foundation/NSURL/init(fileURLWithFileSystemRepresentation:isDirectory:relativeTo:))

Initializes a URL object with a C string representing a local file system path.

[`absoluteURL(withDataRepresentation:relativeTo:)`](/documentation/Foundation/NSURL/absoluteURL(withDataRepresentation:relativeTo:))

Initializes and returns a newly created absolute NSURL using the contents of the given data, relative to a base URL.

[`init(absoluteURLWithDataRepresentation:relativeTo:)`](/documentation/Foundation/NSURL/init(absoluteURLWithDataRepresentation:relativeTo:))

Initializes a newly created absolute NSURL using the contents of the given data, relative to a base URL.

[`URLWithDataRepresentation:relativeToURL:`](/documentation/Foundation/NSURL/URLWithDataRepresentation:relativeToURL:)

Initializes and returns a newly created NSURL using the contents of the given data, relative to a base URL.

[`init(dataRepresentation:relativeTo:)`](/documentation/Foundation/NSURL/init(dataRepresentation:relativeTo:))

Initializes a newly created NSURL using the contents of the given data, relative to a base URL.

[`dataRepresentation`](/documentation/Foundation/NSURL/dataRepresentation)

The data representation of the URL’s relativeString.

### Identifying and Comparing Objects

[isEqual:](/documentation/Foundation/nsurl-isequal)

Returns a Boolean value that indicates whether the receiver and a given object have identical URL strings and base URLs.

### Querying an NSURL

[`checkResourceIsReachableAndReturnError(_:)`](/documentation/Foundation/NSURL/checkResourceIsReachableAndReturnError(_:))

Returns whether the resource pointed to by a file URL can be reached.

[`isFileReferenceURL()`](/documentation/Foundation/NSURL/isFileReferenceURL())

Returns whether the URL is a file reference URL.

[`isFileURL`](/documentation/Foundation/NSURL/isFileURL)

A boolean value that determines whether the receiver is a file URL.

### Accessing the Parts of the URL

[`absoluteString`](/documentation/Foundation/NSURL/absoluteString)

The URL string for the receiver as an absolute URL. (read-only)

[`absoluteURL`](/documentation/Foundation/NSURL/absoluteURL)

An absolute URL that refers to the same resource as the receiver. (read-only)

[`baseURL`](/documentation/Foundation/NSURL/baseURL)

The base URL. (read-only)

[`fileSystemRepresentation`](/documentation/Foundation/NSURL/fileSystemRepresentation)

A C string containing the URL’s file system path. (read-only)

[`fragment`](/documentation/Foundation/NSURL/fragment)

The fragment identifier, conforming to RFC 1808. (read-only)

[`host`](/documentation/Foundation/NSURL/host)

The host, conforming to RFC 1808. (read-only)

[`lastPathComponent`](/documentation/Foundation/NSURL/lastPathComponent)

The last path component. (read-only)

[`parameterString`](/documentation/Foundation/NSURL/parameterString)

The parameter string conforming to RFC 1808. (read-only)

[`password`](/documentation/Foundation/NSURL/password)

The password conforming to RFC 1808. (read-only)

[`path`](/documentation/Foundation/NSURL/path)

The path, conforming to RFC 1808. (read-only)

[`pathComponents`](/documentation/Foundation/NSURL/pathComponents)

An array containing the  path components. (read-only)

[`pathExtension`](/documentation/Foundation/NSURL/pathExtension)

The path extension. (read-only)

[`port`](/documentation/Foundation/NSURL/port)

The port, conforming to RFC 1808.

[`query`](/documentation/Foundation/NSURL/query)

The query string, conforming to RFC 1808.

[`relativePath`](/documentation/Foundation/NSURL/relativePath)

The relative path, conforming to RFC 1808. (read-only)

[`relativeString`](/documentation/Foundation/NSURL/relativeString)

A string representation of the relative portion of the URL. (read-only)

[`resourceSpecifier`](/documentation/Foundation/NSURL/resourceSpecifier)

The resource specifier. (read-only)

[`scheme`](/documentation/Foundation/NSURL/scheme)

The scheme. (read-only)

[`standardized`](/documentation/Foundation/NSURL/standardized)

A copy of the URL with any instances of `".."` or `"."` removed from its path. (read-only)

[`user`](/documentation/Foundation/NSURL/user)

The user name, conforming to RFC 1808.

### Accessing Resource Values

[`resourceValues(forKeys:)`](/documentation/Foundation/NSURL/resourceValues(forKeys:))

Returns the resource values for the properties identified by specified array of keys.

[`getResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/getResourceValue(_:forKey:))

Returns the value of the resource property for the specified key.

[`setResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/setResourceValue(_:forKey:))

Sets the URL’s resource property for a given key to a given value.

[`setResourceValues(_:)`](/documentation/Foundation/NSURL/setResourceValues(_:))

Sets the URL’s resource properties for a given set of keys to a given set of values.

[`removeAllCachedResourceValues()`](/documentation/Foundation/NSURL/removeAllCachedResourceValues())

Removes all cached resource values and temporary resource values from the URL object.

[`removeCachedResourceValue(forKey:)`](/documentation/Foundation/NSURL/removeCachedResourceValue(forKey:))

Removes the cached resource value identified by a given key from the URL object.

[`setTemporaryResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/setTemporaryResourceValue(_:forKey:))

Sets a temporary resource value on the URL object.

[`URLResourceKey`](/documentation/Foundation/URLResourceKey)

Keys that apply to file system URLs.

### Modifying and Converting a File URL

[`filePathURL`](/documentation/Foundation/NSURL/filePathURL)

A file path URL that points to the same resource as the URL object. (read-only)

[`fileReferenceURL()`](/documentation/Foundation/NSURL/fileReferenceURL())

Returns a new file reference URL that points to the same resource as the receiver.

[`appendingPathComponent(_:)`](/documentation/Foundation/NSURL/appendingPathComponent(_:))

Returns a new URL by appending a path component to the original URL.

[`appendingPathComponent(_:isDirectory:)`](/documentation/Foundation/NSURL/appendingPathComponent(_:isDirectory:))

Returns a new URL by appending a path component to the original URL, along with a trailing slash if the component is a directory.

[`appendingPathComponent(_:conformingTo:)`](/documentation/Foundation/NSURL/appendingPathComponent(_:conformingTo:))

Returns a URL by appending the specified path component with the file extension for a uniform type identifier.

[`appendingPathExtension(_:)`](/documentation/Foundation/NSURL/appendingPathExtension(_:))

Returns a new URL by appending a path extension to the original URL.

[`appendingPathExtension(for:)`](/documentation/Foundation/NSURL/appendingPathExtension(for:))

Returns a URL by appending the path extension for a uniform type identifier.

[`deletingLastPathComponent`](/documentation/Foundation/NSURL/deletingLastPathComponent)

A URL you create by removing the last path component from the receiver. (read-only)

[`deletingPathExtension`](/documentation/Foundation/NSURL/deletingPathExtension)

A URL you create by removing the path extension from the receiver, if any. (read-only)

[`resolvingSymlinksInPath`](/documentation/Foundation/NSURL/resolvingSymlinksInPath)

A URL that points to the same resource as the receiver and includes no symbolic links. (read-only)

[`standardizingPath`](/documentation/Foundation/NSURL/standardizingPath)

A URL that points to the same resource as the original URL using an absolute path. (read-only)

[`hasDirectoryPath`](/documentation/Foundation/NSURL/hasDirectoryPath)

A Boolean value that indicates whether the URL string’s path represents a directory.

### Working with Bookmark Data

[`bookmarkData(withContentsOf:)`](/documentation/Foundation/NSURL/bookmarkData(withContentsOf:))

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

[`bookmarkData(options:includingResourceValuesForKeys:relativeTo:)`](/documentation/Foundation/NSURL/bookmarkData(options:includingResourceValuesForKeys:relativeTo:))

Returns a bookmark for the URL, created with specified options and resource values.

[`resourceValues(forKeys:fromBookmarkData:)`](/documentation/Foundation/NSURL/resourceValues(forKeys:fromBookmarkData:))

Returns the resource values for properties identified by a specified array of keys contained in specified bookmark data.

[`writeBookmarkData(_:to:options:)`](/documentation/Foundation/NSURL/writeBookmarkData(_:to:options:))

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

[`startAccessingSecurityScopedResource()`](/documentation/Foundation/NSURL/startAccessingSecurityScopedResource())

In an app that has adopted App Sandbox, makes the resource pointed to by a security-scoped URL available to the app.

[`stopAccessingSecurityScopedResource()`](/documentation/Foundation/NSURL/stopAccessingSecurityScopedResource())

In an app that adopts App Sandbox, revokes access to the resource pointed to by a security-scoped URL.

[`NSURL.BookmarkFileCreationOptions`](/documentation/Foundation/NSURL/BookmarkFileCreationOptions)

Options used when creating file bookmark data

[`NSURL.BookmarkCreationOptions`](/documentation/Foundation/NSURL/BookmarkCreationOptions)

Options used when creating bookmark data.

[`NSURL.BookmarkResolutionOptions`](/documentation/Foundation/NSURL/BookmarkResolutionOptions)

Options used when resolving bookmark data.

### Working with Promised Items

[`checkPromisedItemIsReachableAndReturnError(_:)`](/documentation/Foundation/NSURL/checkPromisedItemIsReachableAndReturnError(_:))

Returns whether the promised item can be reached.

[`getPromisedItemResourceValue(_:forKey:)`](/documentation/Foundation/NSURL/getPromisedItemResourceValue(_:forKey:))

Returns the value of the resource property for the specified key.

[`promisedItemResourceValues(forKeys:)`](/documentation/Foundation/NSURL/promisedItemResourceValues(forKeys:))

Returns the resource values for the properties identified by specified array of keys.

### Working with Pasteboards

[`init(fromPasteboard:)`](/documentation/Foundation/NSURL/init(fromPasteboard:))

Reads an NSURL object off of the specified pasteboard.

[`write(to:)`](/documentation/Foundation/NSURL/write(to:))

Writes the URL to the specified pasteboard.

### Using Quick Looks

[`customPlaygroundQuickLook`](/documentation/Foundation/NSURL/customPlaygroundQuickLook)

A custom playground Quick Look for this instance.

### Constants

[NSURL Schemes](/documentation/Foundation/nsurl-schemes)

The schemes that the `NSURL` class is able to parse.

[NSError userInfo Dictionary Keys](/documentation/Foundation/nserror-userinfo-dictionary-keys)

Keys in the userInfo dictionary of an `NSError` object when certain NSURL methods return an error.

### Deprecated

[`init(scheme:host:path:)`](/documentation/Foundation/NSURL/init(scheme:host:path:))

Initializes a newly created NSURL with a specified scheme, host, and path.

[`URLHandleUsingCache:`](/documentation/Foundation/NSURL/URLHandleUsingCache:)

Returns a URL handle to service the receiver.

[`loadResourceDataNotifyingClient:usingCache:`](/documentation/Foundation/NSURL/loadResourceDataNotifyingClient:usingCache:)

Loads the receiver’s resource data in the background.

[`resourceDataUsingCache:`](/documentation/Foundation/NSURL/resourceDataUsingCache:)

Returns the receiver’s resource data, loading it if necessary.

[`setResourceData:`](/documentation/Foundation/NSURL/setResourceData:)

Attempts to set the resource data for the receiver.

[`propertyForKey:`](/documentation/Foundation/NSURL/propertyForKey:)

Returns the specified property of the receiver’s resource.

[`setProperty:forKey:`](/documentation/Foundation/NSURL/setProperty:forKey:)

Changes the specified property of the receiver’s resource.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)