This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
structTestWeatherView:View{@Stateprivatevar text =""privatelet url =URL(string:"https://wttr.in/?format=3")!var body:someView{Text(text).onAppear {
text =try!String(contentsOf: url)}}}
OK です。
次は、Web クライアントを汎用性のある URLSession に変えます。
structTestWeatherView:View{@Stateprivatevar text =""privatelet url =URL(string:"https://wttr.in/?format=3")!var body:someView{Text(text).task {let(data,_)=try!awaitURLSession.shared.data(from: url)
text =String(data: data, encoding:.utf8)!}}}
ここで、警告がでます。
Passing argument of non-sendable type '(any URLSessionTaskDelegate)?' outside of main actor-isolated context may introduce data races
これは、なんですか。
Passing argument of non-sendable type '(any URLSessionTaskDelegate)?' outside of main actor-isolated context may introduce data races
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters