SAPURLSession supports async/await
source link: https://blogs.sap.com/2022/08/09/sapurlsession-supports-async-await/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SAPURLSession supports async/await
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)
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+
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK