I am trying to build an app for ios to display various festivals daily programs. In this app, I want the user to be notified each time one of the events that compose a festival program is either "added", "modified" or "deleted".
For the database I am using realms cloud service. The structure of my database is the following: I have a Realm object called "Festival". Inside this I have a list of "DailyProgram" objects and inside of each "DailyProgram" I have a list of "Event". I provide a snippet bellow of these objects.
When the app access the Realm Cloud, it downloads an array containing all the different festivals.
I would like to use realm built-in notification system in order to detect changes in the "Event" object.
I tried to implement a Collection Notification on this festival array, but when I make a change in one Event back on the database, the Collection Notification just returns the array index corresponding to the Festival in which that change occurred. And I would like to get information on which particular Event that change occurred as well as what was changed.
class Festival: Object {
@objc dynamic var festivalId: String = UUID().uuidString
@objc dynamic var name: String = ""
@objc dynamic var town: String = ""
@objc dynamic var initialDate: Date = Date()
@objc dynamic var finalDate: Date = Date()
let program = List<DailyProgram>()
override static func primaryKey() -> String? {
return "festivalId"
}
}
class DailyProgram: Object{
@objc dynamic var day: Date = Date()
let events = List<Event>()
}
class Event: Object {
@objc dynamic var name: String = ""
@objc dynamic var local: String = ""
@objc dynamic var time: Date = Date()
}
I am well aware of the existence of Object Notifications in Realm. I think those might be the solution for my problem. I know how to implement an Object Notification on an individual object. However, I don't know how to implement these type of notifications in a case of nested objects.