ios - Multipeer Connectivity send and receive NSManagedObject -
i'm looking send , receive nsmanagedobject through multipeer connectivity framework.
class myobject: nsmanagedobject { @nsmanaged var name: string @nsmanaged var children: nsset
}
i've managed send strings , dictionaries, need send nsmanagedobject nsset. possible?
here's i've tried:
let data = nskeyedarchiver.archiveddatawithrootobject(nsmanagedobject) if session.connectedpeers.count > 0 { var error: nserror? if !session.senddata(data,topeers: session.connectedpeers, withmode: .reliable, error: &error){ println("send error:") println(error) } } else { println("no peers connected!") } func session(session: mcsession!, didreceivedata data: nsdata!, frompeer peerid: mcpeerid!) { nslog("%@", "didreceivedata: \(data.length) bytes") let nsmanagedobject = nskeyedunarchiver.unarchiveobjectwithdata(data) as! myobject }
the problem sending nsmanagedobject
different device has been persisted core data on source device, cannot deserialized , inserted persistent store of target.
i suggest serializing objects nsdictionary
, sending data, , implementing find-or-create correctly insert new managed objects on target device.
Comments
Post a Comment