HomeiOS Developmentios - Reference to captured var in concurrently-executing code

ios – Reference to captured var in concurrently-executing code


I used to be making an attempt out the brand new async/await sample in swift and I got here accross one thing which I discovered it complicated.

struct ContentView: View {
    var physique: some View  {
        Textual content("Hi there World!")
            .process {
                var num = 1

                Activity {
                    print(num)
                }

                Activity {
                    print(num)
                }
            }
    }

    func printScore() async {
        var rating = 1

        Activity { print(rating) }
        Activity { print(rating) }
    }
}

enter image description here

Can somebody please make clear wanting on the above screenshot on why the compiler solely complaints about captured var inside printScore() perform and doesn’t grievance when the identical is being completed utilizing the process modifier on the physique computed property of the ContentView struct (i.e Line 14-24) ?

That is the instance I got here up with and received confused on the compiler conduct.I additionally change the compiler setting “Strict Concurrency Checking” construct setting to “Full” and nonetheless do not see the compiler complaining.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments