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.


@Hatsushira: Thank you so much!

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

Greetings Harry


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.