One Logo Pool Ball
Foundation · IOS API REFERENCE

URL.FormatStyle

struct · iOS 16.0+ · SDK 27.1

struct FormatStyle

A structure that converts between URL instances and their textual representations.

Members (11)

get · iOS 16.0+

parseStrategy

TypeScript
get parseStrategy(): URL_ParseStrategy
Swift declaration
var parseStrategy: URL.ParseStrategy { get }

The parse strategy used by this format style.

method · iOS 16.0+

host

TypeScript
host(strategy?: URL_FormatStyle_HostDisplayOption): URL_FormatStyle
Swift declaration
func host(_ strategy: URL.FormatStyle.HostDisplayOption = .always) -> URL.FormatStyle

Modifies a format style to display a URL's host component in accordance with the provided option. - Parameter strategy: A host display option that indicates when, if ever, to display the host component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

path

TypeScript
path(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func path(_ strategy: URL.FormatStyle.ComponentDisplayOption = .always) -> URL.FormatStyle

Modifies a format style to display a URL's path component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the path component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

port

TypeScript
port(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func port(_ strategy: URL.FormatStyle.ComponentDisplayOption = .omitIfHTTPFamily) -> URL.FormatStyle

Modifies a format style to display a URL's port component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the port component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

user

TypeScript
user(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func user(_ strategy: URL.FormatStyle.ComponentDisplayOption = .never) -> URL.FormatStyle

Modifies a format style to display a URL's user component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the user component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

query

TypeScript
query(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func query(_ strategy: URL.FormatStyle.ComponentDisplayOption = .never) -> URL.FormatStyle

Modifies a format style to display a URL's query component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the query component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

format

TypeScript
format(value: string): string
Swift declaration
func format(_ value: URL) -> String

Formats a URL, using this style. Use this method when you want to create a single style instance, and then use it to format multiple URL instances. The following example creates a custom format style and then uses it to format a variety of URLs in an array: ```swift let style = URL.FormatStyle( scheme: .never, user: .never, password: .never, host: .omitSpecificSubdomains(["www", "mobile", "m."], includeMultiLevelSubdomains: true), port: .never, path: .always, query: .never, fragment: .never) let urls = [ URL(string: "https://www.example.com/path/one")!, URL(string: "https://beta.example.com/path/two")!, URL(string: "https://beta.staging.west.example.com/three")!, URL(string: "https://query.example.com/four?key4=value4")! ] let formatted = urls.map { $0.formatted(style) } // ["example.com/path/one", "beta.example.com/path/two", "west.example.com/three", "query.example.com/four"] ``` To format a single URL value, use the ``URL`` instance method ``URL/formatted(_:)`` passing in an instance of ``URL/FormatStyle``, or ``URL/formatted()`` to use a default style. - Parameter value: The URL to format. - Returns: A string representation of `value`, formatted according to the style's configuration.

init · iOS 16.0+

init

TypeScript
static init(scheme?: URL_FormatStyle_ComponentDisplayOption, user?: URL_FormatStyle_ComponentDisplayOption, password?: URL_FormatStyle_ComponentDisplayOption, host?: URL_FormatStyle_HostDisplayOption, port?: URL_FormatStyle_ComponentDisplayOption, path?: URL_FormatStyle_ComponentDisplayOption, query?: URL_FormatStyle_ComponentDisplayOption, fragment?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
init(scheme: URL.FormatStyle.ComponentDisplayOption = .always, user: URL.FormatStyle.ComponentDisplayOption = .never, password: URL.FormatStyle.ComponentDisplayOption = .never, host: URL.FormatStyle.HostDisplayOption = .always, port: URL.FormatStyle.ComponentDisplayOption = .omitIfHTTPFamily, path: URL.FormatStyle.ComponentDisplayOption = .always, query: URL.FormatStyle.ComponentDisplayOption = .never, fragment: URL.FormatStyle.ComponentDisplayOption = .never)

Creates a new `FormatStyle` with the given configurations. - Parameters: - scheme: The strategy to use for formatting the `scheme`. - user: The strategy to use for formatting the `user`. - password: The strategy to use for formatting the `password`. - host: The strategy to use for formatting the `host`. - port: The strategy to use for formatting the `port`. - path: The strategy to use for formatting the `path`. - query: The strategy to use for formatting the `query`. - fragment: The strategy to use for formatting the `fragment`.

method · iOS 16.0+

scheme

TypeScript
scheme(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func scheme(_ strategy: URL.FormatStyle.ComponentDisplayOption = .always) -> URL.FormatStyle

Modifies a format style to display a URL's scheme component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the scheme. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

fragment

TypeScript
fragment(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func fragment(_ strategy: URL.FormatStyle.ComponentDisplayOption = .never) -> URL.FormatStyle

Modifies a format style to display a URL's fragment component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the fragment component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

method · iOS 16.0+

password

TypeScript
password(strategy?: URL_FormatStyle_ComponentDisplayOption): URL_FormatStyle
Swift declaration
func password(_ strategy: URL.FormatStyle.ComponentDisplayOption = .never) -> URL.FormatStyle

Modifies a format style to display a URL's password component in accordance with the provided option. - Parameter strategy: A component display option that indicates when, if ever, to display the password component. - Returns: A modified ``URL/FormatStyle`` that incorporates the specified behavior.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →