Habits model class
- create an
Habitsclass, a list of Habits. Here we use aRealmSwiftList. As there's also now aSwiftUIList, 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
grouppropery to ourHabitclass:
/Model/Habit.swift
// backlink
@Persisted(originProperty: "habits") var group: LinkingObjects<Habits>