Habits model class
- create an
Habits
class, a list of Habits. Here we use aRealmSwift
List. As there's also now aSwiftUI
List, we need to add the namespaceRealmSwift.List
/Model/Habits.swift
import RealmSwift
class Habits: Object {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var habits = RealmSwift.List<Habit>()
}
- if we want to reference from one habit to the list of habits, we'll a
group
propery to ourHabit
class:
/Model/Habit.swift
// backlink
@Persisted(originProperty: "habits") var group: LinkingObjects<Habits>