UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Caching metadata from ObservableObject in SwiftUI?

Forums > SwiftUI

Hey everyone, I’ve hit a wall with figuring out NSCache in conjunction with MongoDB Realm and ObservableObject. Basically, I have a function that retrieves data related to Plants from an external database and stores it as an object, and that works great. Additionally, I was able to set up another model for caching Image URLs, and I’m able to pass through a URL string from the Plant object retrieved from MongoDB Realm just fine.

The problem is, I can’t seem to figure out how to cache ALL the data from the Realm Object once it’s called - right now, everything’s based on EnvironmentObject/Observable Object, so every single time the view is accessed, the Realm function shoots off and it takes a few seconds to propagate even 5 different objects from Realm. I’d like to avoid that by caching objects altogether.

Would this require shifting data from the ObservableObject Realm Object into CoreData? I’d like to avoid that and stick with NSCache if possible, but would love any advice on the matter!

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.