Originally created by @ghost on GitHub (Nov 29, 2016).
I just implemented the ImportableUniqueObject protocol and its working just fine. Any 'Person' which has the same 'name' is not duplicated. However, 'uniqueIDValue' does not seem to be playing a role in all this, so I'm wondering what its purpose is. In its return value, you can see that I put some random string as it didn't matter what was there, everything works fine. Here is the code I have for it.
import Foundation
import CoreData
import CoreStore
@objc(Person)
public class Person: NSManagedObject, ImportableUniqueObject {
public func update(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws {
print("...")
}
public func didInsert(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws {
self.name = source["name"] as? String
self.id = source["id"] as? String
}
public typealias ImportSource = [String: AnyObject]
public typealias UniqueIDType = NSObject
public class var uniqueIDKeyPath: String {
return "name"
}
public var uniqueIDValue: NSObject {
get { return "SomeRandomString... " as NSObject }
set { }
}
public static func uniqueID(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws -> NSObject? {
return source["name"] as? NSObject
}
}
Originally created by @ghost on GitHub (Nov 29, 2016).
I just implemented the ImportableUniqueObject protocol and its working just fine. Any 'Person' which has the same 'name' is not duplicated. However, 'uniqueIDValue' does not seem to be playing a role in all this, so I'm wondering what its purpose is. In its return value, you can see that I put some random string as it didn't matter what was there, everything works fine. Here is the code I have for it.
import Foundation
import CoreData
import CoreStore
@objc(Person)
public class Person: NSManagedObject, ImportableUniqueObject {
public func update(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws {
print("...")
}
public func didInsert(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws {
self.name = source["name"] as? String
self.id = source["id"] as? String
}
public typealias ImportSource = [String: AnyObject]
public typealias UniqueIDType = NSObject
public class var uniqueIDKeyPath: String {
return "name"
}
public var uniqueIDValue: NSObject {
get { return "SomeRandomString... " as NSObject }
set { }
}
public static func uniqueID(from source: Dictionary<String, AnyObject>, in transaction: BaseDataTransaction) throws -> NSObject? {
return source["name"] as? NSObject
}
}
adam
added the question label 2025-12-29 15:24:44 +01:00
If you assign a random string like in your code, you will never map your source properly to its ID (in this case, source["name"]
@JohnEstropia commented on GitHub (Nov 29, 2016):
@rslim087g You can check how `uniqueIDValue` is used here: https://github.com/JohnEstropia/CoreStore/blob/swift3_develop/Sources/Importing/BaseDataTransaction%2BImporting.swift#L227
If you assign a random string like in your code, you will never map your source properly to its ID (in this case, `source["name"]`
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ghost on GitHub (Nov 29, 2016).
I just implemented the ImportableUniqueObject protocol and its working just fine. Any 'Person' which has the same 'name' is not duplicated. However, 'uniqueIDValue' does not seem to be playing a role in all this, so I'm wondering what its purpose is. In its return value, you can see that I put some random string as it didn't matter what was there, everything works fine. Here is the code I have for it.
import Foundation
import CoreData
import CoreStore
@objc(Person)
public class Person: NSManagedObject, ImportableUniqueObject {
}
@JohnEstropia commented on GitHub (Nov 29, 2016):
@rslim087g You can check how
uniqueIDValueis used here: https://github.com/JohnEstropia/CoreStore/blob/swift3_develop/Sources/Importing/BaseDataTransaction%2BImporting.swift#L227If you assign a random string like in your code, you will never map your source properly to its ID (in this case,
source["name"]@ghost commented on GitHub (Nov 29, 2016):
Thank you for both the library and the response ! Clear as day.