我正在尝试根据收到的Push通知在TabView中切换选项卡。我的TabView看起来像这样:
import SwiftUI
import Combine
struct ContentView: View {
@State var selection = 0
var body: some View {
TabView(selection: $selection){
接收推送通知并尝试更改选项卡:
class SceneDelegate: UIResponder, UIWindowSceneDelegate, UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
(window?.rootViewController?.view as? ContentView)?.selection = 2
这会产生错误-Cannot assign to immutable expression of type 'Int'
。我该如何解决?