Where to start for Core Data relationships

1

Good to everyone, I'm new to Swift, I've been learning for 3 weeks on my own and I'm developing a very simple app to store your clothes

At the moment I have achieved that the user puts in a Data Core the clothes with his photo, brand and name, it is shown in a Cell View, it can be edited, deleted and added, etc ...

Now, in the second part of the application, the idea is that the user can create "sets" with those clothes, that is, if I have put in the previous "Entity" of the Data Core the data of the clothes that I use, I can now use several of these elements to create new sets and that are related in such a way that when erasing, for example, some shoes, they disappear from the sets

At the moment I am investigating how I can make a new Entity as values from the previous Entity and I have only found some one-to-one, one-to-multiple, etc. relationships but I do not know if I should use any bookstore to simplify, find a tutorial that develops a problem similar to mine, etc ...

Any help I would appreciate a lot

Thank you very much for everything

Greetings

    
asked by FlashHardcore 14.10.2017 в 21:54
source

1 answer

1

I hope to answer your question well.

First, clarify that it is an example.

I'll explain:

I have suggested that all objects have attributes in common . That's why I created a parent object called Clothes that has the common attributes of the objects such as color, material and size . . p>

Then I created the objects for example t-shirt, trousers and shoes . Each of them can carry their own attributes that are not possessed by any other object, this is the object orientation .

Then I created the Set object which is nothing more than an object without attributes, it only has relationships 1-1 with the different possible objects such as shoe , T-shirts and pants .

It would be something like this:

I recommend that you put inverse relationships because otherwise you get very annoyed warnings, which I suppose XCode 9 was going to solve but not ...

Now I'll try to explain how to make a parent object and relationships in XCode 9. I think words will suffice, if not, tell me and attach photos.

Parent object: You create an object in the DataModel that has the attributes in common among several objects ( Clothes ). Then you create the objects (for example Shoe ) and you go to the right side menu and between the different options there is one that says: Parent Entity .

There you select Clothes as a parent object. And so with all the objects that you want to have as a father to Clothes .

In terms of relationships ... well, create them you know, to make a relationship is reverse you just have to go to the object of the relationship and create a relationship to the previous object. Let me explain with an example:

Set has a relationship with Shoe .

To return this inverse relationship you just have to create a Shoe relationship with Set and where it says inverse to select the previous relationship.

I hope I helped you!

PS: As a personal contribution, you could try Realm

    
answered by 16.10.2017 / 16:17
source