views:

46

answers:

1

Hi all,

I am starting to have a look at Core Data, as many claiming is the best way to persist data.

I have an already working project with its model and objects, the main purpose of the application is to encapsulate things as attributes (NString,NSObject, Custom Object..ecc) into one main class, give the ability to create many instance of this class then save it to storage, later retrieve and display a table list with all saved instance.

In this case, where my class is already defined (as NSObject extension), what could happen with the introduction of Core Data ? Do I need to rewrite my model ?

For example as a first try I created a model in xcode, then associate my object as entity to it. But some of the attributes that were not using standard such as string, int ...ecc got UNDEFINED as type.

@interface Car {
NSString *name;
WheelsType wtype; <-- undefined
NSDate *buy;
CarColor *color; <-- undefined
}
@end

What does that mean ? Am I able to save just only String,Int,Boolean...ecc but not my Custom Classes ? If not, what the table structure could be ?

thanks

A: 

Custom types in CoreData can be declared transformable, meaning that they'll be transformed to and from instances of NSData. The default value transformer works in many cases, but your classes may require a custom NSValueTransformer.

Edit: Since utilizing CoreData changes how you retrieve your data, it'd be wise to review your model. Read the CoreData documentation and then consider how your objects are accessed and how you can avoid faulting objects and properties that will go unused.

Justin
Thanks that's clear now. Do you think that introducing core data, would make me rewrite or rethink some of the classes and models ? Or it is just a layer that I can plug in, and its only impact is on retrieving and saving ?
Leonardo
Since it impacts how you *retrieve* your data, it'd be wise to review your model. Read the `CoreData` documentation and then consider how your objects are accessed and how you can avoid faulting objects and properties that will go unused. Does this answer your question?
Justin
yes thanks, I also discover myself that is not so straightforward to plug Core Data as I stated here: http://stackoverflow.com/questions/3377694/understanding-nsmanagedobject , if you rewrite your answer including this last comment I can flag question as answered.
Leonardo
I've edited my answer to include the above comment and will answer your linked followup question when I find the time.
Justin