0

because I do not know how to use relationships in core data And I tried many times without success.

I want to create an array as a attribute of an entity
What type of attribute should be?
And how to save the array in the core data And how do I get it?

I would be happy Sample Code

3 Answers 3

2

You really do not want to create an array and store it in Core Data. It will not be searchable and the performance will suffer.

You are far better off building a test project and learning how to use relationships. You treat a relationship object as any other object but it returns a set rather than a single object.

I would suggest reading some of the primer material on Core Data and master relationships otherwise you will not use Core Data at anywhere near its full potential.

Sign up to request clarification or add additional context in comments.

6 Comments

i'm losing my mind My problem is that I started to build a project core data from this link: appcoda.com/core-data-tutorial-update-delete I have files entities, And I can not find instructions explaining how to build a relationship Entities without creating files.
I have her being I want it kind of array, I know it is possible to create another entity that does not have a problem with it. The problem I want this entity will be linked to another entity in the table view And create array entity in any table view all of this without files to entities that possible?
There is no relationship "entity". A relationship is merely a property on an existing object. If you have an Author object with a relationship to Books called "books" you would access it like any other property on an author instance: NSSet *books = author.books.
Your question in your comments is not clear. If you want to set a relationship between two entities you would do so like any other property. If it is a one to one relationship it would be author.book = theBookToReference. If it is a one to many you would do author.books = myNSSetOfBookObjects. Core Data uses the same syntax the rest of Objective-C users.
How can work with a relationship, if the do not have files to entities? Look at the link I wrote the first note, it does not create files (classes) entities
|
1

You can store an NSArray as a Transformable attribute. Then you can use the NSCoding to serialize the array. The advantage of this approach is that it's easy but you can't query into the array because it's stored as a BLOB in the data store. If the array is large, you may have to save or load a lot of data to/from the data store just to read or modify a small part of the collection. So you should work with small Array data.

this is my simple sample. CoreDataWithArraySample

1 Comment

i'm losing my mind My problem is that I started to build a project core data from this link: appcoda.com/core-data-tutorial-update-delete I have files entities, And I can not find instructions explaining how to build a relationship Entities without creating files. I have her being I want it kind of array, I know it is possible to create another entity that does not have a problem with it. The problem I want this entity will be linked to another entity in the table view And create array entity in any table view all of this without files to entities that possible?
0

For that you can use the transformable attribute type in CoreData. In simple terms that attribute type can be thought of as a pointer to any objective-c object that supports NSCoding. NSArray does, so you can assign one of those to that attribute but then for things to work with the persistence store also all the objects you store in the NSArray also need to be NSCoding compliant.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.