Post

Replies

Boosts

Views

Activity

Why Actor-isolated property cannot be passed 'inout' to 'async' function call?
Considering below dummy codes: @MainActor var globalNumber = 0 @MainActor func increase(_ number: inout Int) async { // some async code excluded number += 1 } class Dummy: @unchecked Sendable { @MainActor var number: Int { get { globalNumber } set { globalNumber = newValue } } @MainActor func change() async { await increase(&number) //Actor-isolated property 'number' cannot be passed 'inout' to 'async' function call } } I'm not really trying to make an increasing function like that, this is just an example to make everything happen. As for why number is a computed property, this is to trigger the actor-isolated condition (otherwise, if the property is stored and is a value type, this condition will not be triggered). Under these conditions, in function change(), I got the error: Actor-isolated property 'number' cannot be passed 'inout' to 'async' function call. My question is: Why Actor-isolated property cannot be passed 'inout' to 'async' function call? What is the purpose of this design? If this were allowed, what problems might it cause?
0
0
227
1w
Dose List in SwiftUI reuse itself while scrolling?
I am a beginner in SwiftUI. I try to find some new way to build a page same as UITableView. Some said that List does reuse its cell, but I tried these following code than make the app so laggy. So, the only way to interacting TableView is use representable ? struct TestView: View {     var body: some View {         NavigationView { List {                     ForEach(0..<1000000, id: \.self) { key in                         Text("\(key)")                     }                 }         }     } }
0
0
431
Mar ’23