swift の async / await を試す

swift

Xcode 13 が正式リリースされましたね。

早速 async / await を試してみようと思ったのですが、

以下のエラーがでました。

Async methods call in a function that does not support concurrency

Async await in Swift explained with code examples – 2021年7月15日
https://www.avanderlee.com/swift/async-await

なんか、func の書き方を

func fetchData() async {

   await .....
}

みたいにしないといけないようです。

もう少し詳細にわかったら追記します。

Async/await – swift-evolution
https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md

Concurrency
https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html

Swift Concurrency チートシート – 2021.9.20
https://zenn.dev/koher/articles/swift-concurrency-cheatsheet

SwiftUIのチートシート – 2021年7月22日
https://qiita.com/hcrane/items/eb847ca7fb7a0b9e8073

Swift Concurrency まとめ
https://zenn.dev/akkyie/articles/swift-concurrency

なんか、Task で囲まないといけないみたいです。

Task {
  await someFunc()
}

[iOS] Swift でも async / await したい – 2021.9.7
https://dev.classmethod.jp/articles/try-async-await-actor-in-swift

iOS15用SwiftUIでのAsync / Await入門
SwiftUIアプリでasync / awaitを使用する方法を学ぶ
https://ichi.pro/ios-15-yo-swiftui-de-no-async-await-nyumon-270651314285131

Swift now supports asynchronous functions — a pattern commonly known as async/await. Discover how the
new syntax can make your code easier to read and understand. Learn what happens when a function suspends, and find out how to adapt existing completion handlers to asynchronous functions.

Meet async/await in Swift
https://developer.apple.com/videos/play/wwdc2021/10132

Swift5.5からのasync_awaitを学びたい方へ
https://lfk-devpods.linecorp.com/episode/3

async/awaitとアクタをサポートするSwift 5.5
https://www.infoq.com/jp/news/2021/07/swift-async-await-actors

Connecting async/await to other Swift code
https://www.swiftbysundell.com/articles/connecting-async-await-with-other-swift-code

Async let explained: call async functions in parallel – Aug 10, 2021
https://www.avanderlee.com/swift/async-let-asynchronous-functions-in-parallel

How to use continuations to convert completion handlers into async functions – June 24th 2021
https://www.hackingwithswift.com/quick-start/concurrency/how-to-use-continuations-to-convert-completion-handlers-into-async-functions

How to fix the error “async call in a function that does not support concurrency”
https://www.hackingwithswift.com/quick-start/concurrency/how-to-fix-the-error-async-call-in-a-function-that-does-not-support-concurrency

Understanding async/await in Swift – Jun 16, 2021
https://www.andyibanez.com/posts/understanding-async-await-in-swift

What’s new in Swift 5.5?
https://www.hackingwithswift.com/articles/233/whats-new-in-swift-5-5

‘async’ call in a function that does not support concurrency swift ios Xcode async/await
https://stackoverflow.com/questions/67925525/async-call-in-a-function-that-does-not-support-concurrency-swift-ios-xcode-asy

jakob/async-await-example.md
https://gist.github.com/jakob/22c9725caac5125c1273ece93cc2e1e7

Swift concurrency_ Update a sample app – WWDC21 – Videos – Apple Developer
https://developer.apple.com/videos/play/wwdc2021/10194

Meet async/await in Swift – Apple Developer
https://developer.apple.com/videos/play/wwdc2021/10132

Proposalには載っていないSwift 5のasync/awaitが素晴らしいと思う理論的背景 – 2021年01月21日
https://qiita.com/koher/items/29357b5e00aec1962601

async/await in SwiftUI – Jun 21 2021
https://www.raywenderlich.com/25013447-async-await-in-swiftui

SwiftUIを楽にするSwift 5.3の新機能 – 2020.09.18
https://zenn.dev/koher/articles/swift53-for-swiftui

SwiftUI移行について真剣に考える
https://zenn.dev/rockname/articles/85f566b089d7a6

Swift先輩
https://swiftsenpai.com

Lee Kah Seng

SwiftでAsync / Awaitを使用してネットワークリクエストを行う
https://ichi.pro/swift-de-async-await-o-shiyoshite-nettowa-ku-rikuesuto-o-okonau-118027862007658

上記記事のサンプルコード

LeeKahSeng/SwiftSenpai-Swift-Concurrency
https://github.com/LeeKahSeng/SwiftSenpai-Swift-Concurrency

withTaskGroup

Starts a new task group which provides a scope in which a dynamic number of tasks may be created.

withTaskGroup – Apple Developer
https://developer.apple.com/documentation/swift/3814991-withtaskgroup

SwiftUIを学ぶのにおすすめの本

SwiftUI開発レシピ iOS 14 対応

SwiftUI iPhoneアプリ開発入門ノート[2020] iOS 14 対応

SwiftUI 徹底入門

SwiftUIではじめるiPhoneアプリプログラミング入門

iOS/macOS UIフレームワーク SwiftUIプログラミング

コメント

タイトルとURLをコピーしました