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

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      

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.