开发者

adding created instances to CoreData

开发者 https://www.devze.com 2023-01-05 10:40 出处:网络
I just first tried out core data right now. I created an App which loads Locations from a Server and creates by using a JSON-Parser dynamically Model-Instances of Class \"Location\". Works fine and n

I just first tried out core data right now.

I created an App which loads Locations from a Server and creates by using a JSON-Parser dynamically Model-Instances of Class "Location". Works fine and no problems.

Now i need to store some locations as favorizedLocations localy on the client. Therefore i want to use CoreData. I had set up a LocationsDetailView with a Button "Add To favorites". And the next things which are supposed to happen are the "Unkown Things" now.

- (void)addFavorite{
LogForGUI(@"TODO Add Favorit with name %@ to Core Data", **objTheLocation**.strAdr);
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];

// If appropriate, configure the new managed object.
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];...
开发者_运维问答

I have created a Location.xcdatamodel the Location.h Modelclass. I had to remove the Arrays and Dictionaries within the xcdatamodel because they required a Type and Array was not available (obviously).

So what i want: I want to bring my already created Model Instance in the CoreData World without setting all properties.

And second question: how can i handle arrays and dictionaries with core data.


First, you don't handle arrays and dictionaries in Core Data. Core Data is your object graph.

As for your first question, what do you mean by your model instance? If you created a xcdatamodel, it will get compiled into a mom file and placed in your Resources folder. Using the template Core Data code you can then load that mom file and create the Core Data stack.

If you are not referring to the xcdatamodel then please clarify your question.

Update

I strongly suggest that you re-read the Core Data documentation because your implementation is not going to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号