I am trying to implement below scenario, but i am facing the issue
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>()
}
I have a comments model which has non optional properties in which childComments is List of same Comments model class. In this when i declare dynamic var childComments = List<CommentsModel>()
it shows me Property cannot be marked dynamic because its type cannot be represented in Objective-C.
Please help me how to achieve my requirement
Just to make it more understandable how you can add data to the list although its declared as let
.
import Foundation
import RealmSwift
import Realm
class Goal: Object {
//List that holds all the Events of this goal
let listOfEvents = List<CalEvent>()
required public convenience init(eventList: List<CalEvent>) {
self.init()
for event in eventList {
//Append the date here
self.listOfEvents.append(i)
}
}
}
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.
Learn more in Docs.
So you should declare childComments
this way:
let childComments = List<CommentsModel>()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With