What is the role of UniqueIdValue. #108

Closed
opened 2025-12-29 15:24:44 +01:00 by adam · 2 comments
Owner

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
adam closed this issue 2025-12-29 15:24:44 +01:00
Author
Owner

@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"]

@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"]`
Author
Owner

@ghost commented on GitHub (Nov 29, 2016):

Thank you for both the library and the response ! Clear as day.

@ghost commented on GitHub (Nov 29, 2016): Thank you for both the library and the response ! Clear as day.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#108