Skip to content

asyncData(with_method_headers_body_)

MarcoDotIO edited this page Apr 25, 2023 · 1 revision

asyncData(with:method:headers:body:)

Takes a URL input, along with header information, and converts it into a URLRequest; and fetches the data using an Async Await wrapper for the older dataTask handler.

public func asyncData(
        with url: URL,
        method: HTTPMethod = .get,
        headers: [String: String] = [:],
        body: Data? = nil
    )

Parameters

  • url: URL to convert to a URLRequest.
  • method: Input can be either a .get or a .post method, with the default being .get.
  • headers: Header data for the request that uses a [string:string] dictionary, and the default is set to an empty dictionary.
  • body: Body data that defaults to nil.

Returns

The data that was fetched typed as a Data object.

Types
Protocols
Global Variables
Global Functions
Extensions
Clone this wiki locally