gpt4 book ai didi

swift - Realm - 属性不能标记为动态,因为它的类型不能在 Objective-C 中表示

转载 作者:IT王子 更新时间:2023-10-29 05:36:21 26 4
gpt4 key购买 nike

我正在尝试实现以下场景,但我遇到了问题

class CommentsModel: Object {
dynamic var commentId = ""
dynamic var ownerId: UserModel?
dynamic var treeLevel = 0
dynamic var message = ""
dynamic var modifiedTs = NSDate()
dynamic var createdTs = NSDate()

//facing issue here
dynamic var childComments = List<CommentsModel>()
}

我有一个评论模型,它具有非可选属性,其中 childComments 是相同评论模型类的列表。在此当我声明dynamic var childComments = List<CommentsModel>()

it shows me Property cannot be marked dynamic because its type cannot be represented in Objective-C.

请帮助我如何实现我的要求

最佳答案

List and RealmOptional properties cannot be declared as dynamic because generic properties cannot be represented in the Objective‑C runtime, which is used for dynamic dispatch of dynamic properties, and should always be declared with let.

了解更多信息 Docs .

所以你应该这样声明childComments:

let childComments = List<CommentsModel>()

关于swift - Realm - 属性不能标记为动态,因为它的类型不能在 Objective-C 中表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40925192/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com