I am trying to figure out how to set up my core-data objects.
I want to load all of the xml into the core-data when the app first loads and I am trying to figure out how to do that. I am currently reading Creating and Deleting Managed Objects
from the apples developer library.
Am I right in assuming that this example is how to put things into the core-data object?
insertNewObjectForEntityForName:inManagedObjectContext:
NSManagedObject *newEmployee = [NSEntityDescription
insertNewObjectForEntityForName:@"Employee"
inManagedObjectContext:context];
If so, how would I implement this with nsxmlparser? would I call it from parserDidEndDocument?
any examples would be great.
There are numerous examples of parsing XML into objects available on SO and via Google.
What you need to realize is that Core Data is all about dealing with Objects. In any example of parsing XML and you want to create an object you would create a
NSManagedObjectinstead with the-insertmethod you show in your question.The question of ‘when do I create the object’ is impossible to answer generically other than “depends”. Build your data model so that the objects make sense based on the data you are pasting. Then as you are flowing through the xml you will know when it makes sense to create an object. Most likely it would be in one of several calls to
-parser:didStartElement:namespaceURI:qualifiedName:attributes:.