TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Core Data Related Entities Selection Storage Best Practice

Forums > SwiftUI

I have 2 entities, (car) model and (car) manufacturer - 1 manufacturer can have many models, a model only has 1 manufacturer.

I have 2 fetch requests, one to each entity.

I allow the user to choose a car brand (to filter out models in a list), and I'd like to save this selection between sessions - what's the best practice for this?

I've tried:

  • having a boolean column in the manufacturer entity storing if it is selected
  • having a separate core data entity with a single row in it, linked to the selected manufacturer
  • saving the selected manufacturer's UUID to a UserDefault and filtering on that

    None of these feel like the correct method and all have hacks required to make them work.

    Can anyone help, or point me in the right direction? Thanks in advace.

2      

This is exactly the kind of thing that UserDefaults is intended for.

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

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.