无法使用@Model存储数据

问题描述 投票:0回答:1

获取

枚举“模型”不能用作模型的属性

当我在 SwiftUI 中用 @model 标记我的类时出错

enum Status: Codable {
    case active
    case inactive(reason: String)
}

@Model class User {
    var name: String
    var age: Int
    var status: Status

    init(name: String, age: Int, status: Status) {
        self.name = name
        self.age = age
        self.status = status
    }
}

ios swift database swiftui swift-data
1个回答
0
投票

我将目标版本更新为 17.0.0 和 Swift5 并解决了问题,但现在我在模型中遇到这些错误enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.