swift 函式宣告不透明的传回型别'some View',但其主体中的传回陈述式没有相符的基础型别

tvz2xvvm  于 2022-12-03  发布在  Swift
关注(0)|答案(1)|浏览(104)

我在var视图中遇到错误:一些视图{.
第一个
我尝试更改var视图:一些视图var视图:any View错误消失,但我正在调用HomeButtons.view我收到此错误消息:* 类型'any View'不能符合'View'*

bbmckpt7

bbmckpt71#

您必须将变量设为@ViewBuilder并移除return

enum HomeButtons: Int, Hashable, CaseIterable{
    case registerSignal = 1
    case setAlarm = 2
    case tV = 3
    case test = 4
    
    var image: String{
        switch self{
        case .registerSignal:
            return "wave.3.backward"
        case .setAlarm:
            return "alarm.fill"
        case .tV:
            return "tv.fill"
        case .test:
            return "av.remote.fill"
        }
    }
    var text: String{
        switch self{
        case .registerSignal:
            return "Register Signal for TV"
        case .setAlarm:
            return "Set up Alarm"
        case .tV:
            return "TV and Sequences"
        case .test:
            return "Test Device"
        }
    }
    @ViewBuilder var view: some View{
        switch self{
        case .registerSignal:
            RegisterView(title: self.text)
        case .setAlarm:
            Text("Set up Alarm")
        case .tV:
            Text("TV and Sequences")
        case .test:
            Text("Test Device")
        }
    }
}

相关问题