NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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

   

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.

1      

@Hatsushira: Thank you so much!

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

Greetings Harry

1      

Hacking with Swift is sponsored by Stream

SPONSORED Build Chat messaging quickly with Stream Chat. The Stream iOS Chat SDK is highly flexible, customizable, and crazy optimized for performance. Take advantage of this top-notch developer experience, get started for free today!

Click here

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

Reply to this topic…

You need to create an account or log in to reply.

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.