objective c - ObjCMongoDB framework and SyncServices in OSX -


i'm looking pointers on how keep coredata model in sync mongodb. i'm leveraging objcmongodb framework , can create objects in core data follows:

coredataobj = [bsondecoder decodemanagedobjectwithclass:[hostname class]                                                 context:[self managedobjectcontext]                                                    data:[bson_host datavalue]]; 

unfortunately when re-import mongodb copy of same objects made , stored.

i'm not sure if using objcmongodb framework incorrectly or if need using syncservices import data coredata model?

can guide me or provide example?

objcmongodb (of i'm author) performs deserialization core data, but, @ present, not deduplication or syncing. treats bson documents simple ordered dictionaries, without sense of identification attribute. in particular, treats _id other key.

you can behavior want you'll need implement yourself.

the easiest way implement -awakeafterusingcoder: or -awakeafterusingbsondecoder: – doesn't matter – in nsmanagedobject subclass. decoder automatically invoke these.

self new, deserialized object. run fetch request existing entry self duplicates. if find one, apply properties existing object, delete new object context, , return existing entry. if don't find one, return self.

you can use -dictionarywithvaluesforkeys: , -setvaluesforkeyswithdictionary: accomplish this, , list of keys method this:

+ (nsarray *) persistentkeysforentity:(nsentitydescription *) entity {     nsmutablearray *result = [nsmutablearray array];     (nspropertydescription *pdesc in [entity properties]) {         if ([pdesc istransient]) continue;         [result addobject:pdesc.name];     }     return [result copy]; } 

added: if don't need exclude transient attributes, can apply values 1 line:

[target setvaluesforkeyswithdictionary:[self dictionarywithvaluesforkeys:self.entity.attributesbyname.allkeys]]; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -