首页 > 解决方案 > 函数声明一个不透明的返回类型

问题描述

我的 SwiftUI 结构中有以下函数

private func datePicker() -> some View {
    if #available(iOS 14.0, *) {
        return DatePickerCompactView(date: $modelController.eventModel.startAt)
    } else {
        return DatePickerWheelView(date: $modelController.eventModel.startAt)
    }
}

但是,它给了我这个错误:

Function declares an opaque return type, but the return statements in its body do not have matching underlying types

为什么?它们都是一种View?我该如何解决?

标签: iosswiftui

解决方案


推荐阅读