The following code inside an newly created iOS App project results in the following warning:
Non-sendable type 'Notification?' returned by call from main actor-isolated context to non-isolated instance method 'next()' cannot cross actor boundary
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.padding()
.task{
for await _ in NotificationCenter.default.notifications(named: UIDevice.orientationDidChangeNotification){
print("orientation changed")
}
}
}
}
What is the correct way to handle this or is it an API error?
Isn't NotificationCenter.default.notifications(named: ...) exactly meant to be used with for ... await aka. next()?
9
6
8k