0

I'm making an app (Swift 4), where a Realm database is created in one View Controller, but I cannot seem to access the objects from a different view controller. Essentially, a user rates a meal in the first view controller, and the meal name and a corresponding rating is stored as a Realm object to a database. I want to show a user a chart of the rated meals in a separate view controller (like a "Favourites" view controller), however I can't access the objects from that second view controller. How should I go about this? Thanks!

1 Answers1

1

The database can be accessed anywhere with

do {
     let r = try Realm() 
     let stored = r.objects(ClassName.self)
     print(stored)
}
catch {
     print(error)
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87