SAP BTP SDK for iOS 8.0.1 includes the first step of supporting
Swift Modern Concurrency by introducing the following
async
functions on
SAPURLSession
:
- func data(for request: URLRequest) async throws -> (Data, URLResponse)
- func data(from url: URL) async throws -> (Data, URLResponse)
- func download(for request: URLRequest) async throws -> (URL, URLResponse)
- func download(from url: URL) async throws -> (URL, URLResponse)
- func upload(for request: URLRequest, from bodyData: Data) async throws -> (Data, URLResponse)
- func upload(for request: URLRequest, fromFile fileURL: URL) async throws -> (Data, URLResponse)
When calling an asynchronous method, execution suspends until that method returns. You write
await
in front of the call to mark the suspension point.
func yourCustomAsyncFunction() async throws {
let request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/todos/1")!)
let sapURLSession = SAPURLSession()
let (data, urlResponse) = try await sapURLSession.data(for: request)
let article = try JSONDecoder().decode(Article.self, from: data)
print(article.title) // "delectus aut autem"
}
Please share your feedback with me on which other APIs of the SAP BTP SDK for iOS you'd like to see the offering of
async
functions.
You can obtain the new SAP BTP SDK for iOS 8.0.1 binary frameworks through
Swift Package Manager or
CocoaPods.
You can also download the latest SAP BTP SDK for iOS Assistant app (which includes the latest binary frameworks) from
SAP Software Download Center or from the
Trials Download Page (
coming soon)
Xcode 13.2+ is required for SAP BTP SDK for iOS 8.0+