Xcode 13.2 was release with a new feature.
- You can now use Swift Concurrency in applications that deploy to macOS Catalina 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes
async
/await
, actors, global actors, structured concurrency, and the task APIs. (70738378)
However, when in real practice, I found that Apple's APIs were still requesting higher OSes.
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension URLSession {
/// Convenience method to load data using an URLRequest, creates and resumes an URLSessionDataTask internally.
///
/// - Parameter request: The URLRequest for which to load data.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
public func data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse)
/// Convenience method to load data using an URL, creates and resumes an URLSessionDataTask internally.
///
/// - Parameter url: The URL for which to load data.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
public func data(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse)
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally.
///
/// - Parameter request: The URLRequest for which to upload data.
/// - Parameter fileURL: File to upload.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
public func upload(for request: URLRequest, fromFile fileURL: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse)
/// Convenience method to upload data using an URLRequest, creates and resumes an URLSessionUploadTask internally.
///
/// - Parameter request: The URLRequest for which to upload data.
/// - Parameter bodyData: Data to upload.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
That means we still could not get the full benefit of async/await with old systems. Will Apple just leave APIs like that? Or we could use third-party APIs to replace?