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

SOLVED: Design of Core Data model and relationships

Forums > SwiftUI

Hey guys,

let's say I'm writing an app to manage recipes for smoothies. The user can create various ingredients (let's say fruits) and then various recipes with theese fruits.

Right now I got two entities in my Core Data model:

  • Fruit: id, name
  • Recipe: id, name

But I struggle how to set it up when I'd like to store not only that "Smoothie1" contains "apple" and "peach" but 500g of apple and 100g of peach. How do I handle this?

Thanks a lot for your help! Harry

2      

For this one you need an additional entity. This entity (aka table) has a 1:m relationship to your Fruit and Recipe entities and one attribute field of the amount.

3      

@Hatsushira: Thank you so much!

I've been thinking about this but was very unsure if this would be the right approach!

Greetings Harry

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.