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      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.