I import unique objects from the server and at the same time create offline local objects with iOSLocalId which is my offline local id.
I use this func for unique import:
public class func uniqueID(from source: ImportSource, in transaction: BaseDataTransaction) throws -> UniqueIDType? {
return source["id"] as? UniqueIDType
}
my question is can I specify few uniqueIDs like
public class func uniqueID(from source: ImportSource, in transaction: BaseDataTransaction) throws -> UniqueIDType? {
return source["iOSLocalId"] as? UniqueIDType
}
I need this for binding two objects. Local (which was created offline) and the same received from server.
So the workflow is next:
- Cerate local object which contains only
iOSLocalIdbut does not contain server id as we work offline for example - When connection appears to be online push local object to server.
- When API return back created object on the server sync local and server object.
In this case I need somehow tells CoreStore that I have two unique ids, one is local which server also pass back to me and one is server id for the same object.
But maybe there is another approach as well.
For sure I can write my own Service which will search for already exist local object and update them.
Maybe I can use some of this function:
public static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
return shouldUpdate(from: source, in: transaction)
}
public static func shouldUpdate(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
return true
}
But as I said I need to update every time I found server id, but in case of offline sync, I also have local id and then there is a problem of determining unique id.