Skip to content

Structure

URL

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
A value that identifies the location of a resource, such as an item on a remote server or the path to a local file.
struct URL

Overview

You can 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 URLs to other APIs to retrieve the contents of those URLs. For example, you can use URLSession and its related classes to access the contents of remote resources.

URLs 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 a URL instead of a pathname as the file reference. For example, you can get the contents of a local file URL as String by calling init(contentsOf:encoding:), or as a Data by calling init(contentsOf:options:).

As a convenience, you can use Swift’s async-await syntax to asynchronously access the contents of a URL through the resourceBytes and lines properties. These properties use the shared URLSession instance to load the resource.

Topics

Structures

  • struct Template
    A template for constructing a URL from variable expansions.

Operators

Initializers

Instance Properties

Instance Methods

Type Properties

Type Methods

Enumerations

  • enum DirectoryHint
    A hint to URL file APIs for handling paths that may reference directories.

Default Implementations

Relationships

Conforms To

  • Configuration.ExpressibleByConfigString
  • Foundation.ReferenceConvertible
  • MultipartKit.MultipartPartConvertible
  • Swift.Copyable
  • Swift.CustomDebugStringConvertible
  • Swift.CustomPlaygroundDisplayConvertible
  • Swift.CustomStringConvertible
  • Swift.Decodable
  • Swift.Encodable
  • Swift.Equatable
  • Swift.Escapable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype