LAST CHANCE: Save 50% on all my Swift books and bundles! >>

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      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free 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.