How to set NSManagedObjectID manually?

I want to sync master data on iPhone with MongoDB on a Sinatra server.

When the iPhone receives a message from the Node.js chat server, the message contains the sender of the BSON ObjectId (string). For the iPhone to save this message, I find the user with the same Id in Core Data. I want to do something like objectWithID. In other words, I want to set the NSManagedObjectID as the same as the MongoDB BSON ObjectIds. Another thing that I would check is the absence of users with the sender ID in the managedObjectContext file, I will take it from the persistentStore, and if it does not exist, I will create it. This must be done in order to maintain communication between Message and Sender. Perhaps I should just save the sender attribute of the Message object as my BSON ObjectId as a string, and not as a custom NSManagedObject.

What do you recommend? Should I just use MongoDB on iPhone too? I just realized that there is an Objective-C driver for this. But I was just starting to get Core Data, and it has cool things (like undo support) that I can use ... Now I just use it for easy collection and persistent storage, so I can replace it. But I plan to implement the withdrawal of support in the future, simply because I consider this a good convenience. I prefer the undo option rather than responding to a confirmation pop-up window, for example, I like how GMail allows you to cancel sending or cancel deleting messages, etc.

Thank!

Matt

+3
source share
1

. , externalID -, , .

. , Core Data. , , .

+3

Source: https://habr.com/ru/post/1769930/


All Articles