Meet AsyncSequence

RSS for tag

Discuss the WWDC21 session Meet AsyncSequence.

View Session

Posts under wwdc21-10058 tag

4 Posts
Sort by:
Post marked as solved
1 Replies
249 Views
I have a table to which I've added a refreshControl and when I pull down the table to refresh the data, I reset the array that feeds the table with data and then immediately request new data through an API call. Until now, I have used completion handlers and protocols to get the data into the table view but I want to move the logic to async/await because of the complexity needed by the network calls and the pyramid of nested closures. Populating the view in viewDidLoad works fine but with pullToRefresh selector I get an error: Thread 1: EXC_BAD_ACCESS (code=1, address=0xbcf917df8160) override func viewDidLoad() {     super.viewDidLoad()     setupView()     setupTableView()     setupTableRefreshControl()     Task {       await getBalances() //async network call       myTable.reloadData()     }   }    func setupTableRefreshControl() {     myTable.refreshControl = UIRefreshControl()     myTable.refreshControl?.addTarget(self, action: #selector(didPullToRefresh), for: .valueChanged)   } Code that crashes app:    @objc func didPullToRefresh() async {     balance.reset() // reset array to []     Task {       await getBalances() //async network call       myTable.reloadData()     }   }
Posted
by crsvld.
Last updated
.
Post not yet marked as solved
3 Replies
1.6k Views
In the Meet AsyncSequence talk, there's a very cool use case that's shown in one of the slides - the new notifications property on NotificationCenter is an async sequence and the code sample does something like: let notification = await center.notifications(named: ....).first { ... } This seems really intriguing and useful to me but I had a few questions about the details of how this works: What is the type of notification in this snippet? A Task? Where would I store this value? What context should this be invoked in, especially if I want to have a long-running notification filter running that will remain active for the lifetime of the app? Basically, I'm curious to see an example of the code surrounding this snippet.
Posted Last updated
.
Post not yet marked as solved
0 Replies
260 Views
Hi, I'd like to start playing around with the new Swift Concurrency framework in a Swift Package, but I cannot use AsyncSequence. AsyncSequence is not available despite I'm using swift-tools-version:5.5 in my package manifest.
Posted
by vale_mac.
Last updated
.