Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Core Data - Relationships

I’m guessing this is a basic question and hopefully someone will be able to point me in the right direction to some sample code, so my question….

I want/have created a core data model that has a parent child relationship, one to many, what I would like to know is what is the correct way to insert child records if the parent already exists. What I’m struggling to understand is how the parent relationship is created when only inserting child records.

Hopefully this makes sense, thanks for any help.

like image 868
Duncan Hill Avatar asked Feb 29 '12 10:02

Duncan Hill


People also ask

What are relationships in Core Data?

Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.

Is Core Data a relational database?

What you need to know is that Core Data is not a database. That said, when working with Core Data it acts as a relational database hence the confusion. Core Data is a persistence solution for Apple's platforms and it supports several types of persistent stores, including SQLite.

What is iOS Core Data?

Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0. It allows data organized by the relational entity–attribute model to be serialized into XML, binary, or SQLite stores.


2 Answers

Here You have a series of 3 tutorials: RayWenderlich: Core Data Tutorial

Here a sample app: iPhoneCoreDataRecipes with a more complex data model

Here a Core Data tutorial – One to Many Relationship

Sorry I not respond to your question in his totally. I'm also starting with Core Data, so If You find a good intermediate tuturial, please let me know.

EDIT: A nice article: Core Data Class Overview

like image 82
Frade Avatar answered Sep 28 '22 02:09

Frade


So you'll have Parent and Child. Child will contain a Parent *parentobject while Parent will contain a NSSet *children. Whenever you set the relationship correct in the Datamodel the relationship will be applied automatically when you fill the children set with Child objects.

Please check Articles here

like image 32
ggfela Avatar answered Sep 28 '22 00:09

ggfela