How can I modify my my RestKit managed object before it is saved via Core Data? - objective-c

I have RestKit setup nicely with a Core Data managed object backing but I have some fields which are not present on the server, only in the local model class.
How can I set these fields before the object is persisted. Is there something like a 'willSave' delegate method I can implement?
Thanks

I don't quite understand what you want to accomplish, but you can override willSave in NSManagedObject. The docs give a good explanation of what it does.

If you want to modify the incoming data before you save it, you should consider willMapData

Related

vb.net serialization of system objects?

I am working with sending objects over network. I have it working with custom objects just fine but my question is can I serialize system objects? For example I want to serialize the System.Net.NetworkInformation.NetworkInterface object on one computer and send it to another so I can load all of its properties easily. Is this possible? This doesn't seem to work:
<Serializable()> NIC As System.Net.NetworkInformation.NetworkInterface
Thanks in advance
An object type has to be designed to be serializable, and marked so in it's original code. You will need to build your own object to keep the properties that you care about, mark it serializable, and use that.

Efficiency when handling Core Data Model Object

I'm retro-fitting core data around an existing project and I would like to know which is better for efficiency reasons.
a) Create a model object with an attribute that is of the type of my current model class, then make the object transformable to NSData.
or
b) Subclass NSManagedObject, give it all the ivars of my model object and on fetch / insert do a translating to a model object (fetch) or an NSManagedObject (insert).
Thanks,
Tim
It seems like you don't really understand the purpose of core data. Core data is a mature object graph that can be attached to a persistent store, like SQLite. Whenever you fetch something out of core data, it is already a model object. You use the NSManagedObject as your models, there's no real reason to pull the data out of the NSManagedObject and into a different object.
Before you go further, I recommend that you take a hard look at http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/coredata/cdprogrammingguide.html

Model Object From Both Core Data & External Source

I am building an app where my primary model objects can either be fetched from a Core Data store or from an external source (public API via internet - > JSON - > object). I'm new to Core Data so my question is can I just take my model object as it stands now and make its superclass NSManagedObject? I'd guess that I'd need to make sure my model's properties match the names and types of the data model entities for this to happen. I don't want to have to use two different model objects in the app - one when I fetch from the core data store and one when I fetch from the internet API.
Is there anything else I'd need to do to make my already built model objects compatible for use with core data?
Any guidance or advice would be much appreciated.
Regards,
Craig
You can add some business logic to your object (subclass of NSManagedObject) to enable to creation of such an object from data (ie an NSDictionary of values to be used). The crux will be deciding whether you want those objects managed/saved to your local datastore or not.
I highly recommend becoming familiar with NSManagedObjectContext: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectContext_Class/NSManagedObjectContext.html
What I have done in a couple of products is just deal with core data objects, and initialize them from data that I pull from the web service. That way you only have apples. Another option would be to make a protocol that defines the behavior of the analogous classes. You would be tempted to make one the subclass of the other, but that could get complicated, depending on your persistence requirements.

Mapping obj-c object to sqlite database

Im looking for a simple (if I can call it that) mapping tool for obj-c, that maps objects and their relationships to a sqlite database. Is there any out there that acts like db4o for java? I havent found anything on google, and I think its because Im not completly sure of where to look and what to look for.
Hope someone can help, because I dont want to write my own mapping tool to sqlite.
EDIT
it seems like entropyDb does the job. http://code.google.com/p/entropydb/. But Im not sure yet.
I dont quite understand this line: "One cannot store instances of Cocoa classes directly. Collections (NSArray, NSSet, NSDictionary) can be stored if they are instance variables of custom objects." I read it like I cant store arrays and sets if they are instance variables of a custom object.
You're looking for Core Data, which is part of the iPhone SDK.

How do I localise the default value of attribute in a Core Data Entity

If I was creating an entity with a non-optional string attribute called, say, "name", I would put "Untitled" as the default. How could I localise this default value?
I could subclass the entity and and use NSLocalizedString in awakeFromInsert to do this. But I was wondering if there was another way.
Edit:
If this is the only way, then I'm fine with it. Just curious.
I think awakeFromInsert is the only way
You can try using -[NSEntityDescription attributesByName]. This will give you back an NSDictionary of NSAttributeDescription objects. You can then pull the one you want and use -[NSAttributeDescription setDefaultValue:] on it.
You can localize most aspects of a managed object model, including entity and property names and error messages. See here: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html#//apple_ref/doc/uid/TP40005190-SW13