Identifiable <=> UniqueIDType mapping / interaction #331

Open
opened 2025-12-29 15:29:17 +01:00 by adam · 3 comments
Owner

Originally created by @IdoRabin on GitHub (Jun 2, 2020).

Considering the introduction of identifiable is swift

one can imagine an extension for ImportableUniqueObject leveraging situations where ImportSource is Identifiable, using ImportSource.ID in relation to UniqueIDType, uniqueIDKeyPath and uniqueIDValue

I've implemented a crude base class for a DBTable, but am sure one can create a much better thingie as an extension to the ImportableUniqueObject protocol..

class DBTable<Entity:Codable & Hashable & Identifiable, DBEntity:NSManagedObject & ImportableUniqueObject> {
...
}
Originally created by @IdoRabin on GitHub (Jun 2, 2020). Considering the introduction of `identifiable` is swift one can imagine an extension for `ImportableUniqueObject` leveraging situations where `ImportSource is Identifiable`, using `ImportSource.ID` in relation to `UniqueIDType`, `uniqueIDKeyPath` and `uniqueIDValue` I've implemented a crude base class for a DBTable, but am sure one can create a much better thingie as an extension to the `ImportableUniqueObject` protocol.. ``` class DBTable<Entity:Codable & Hashable & Identifiable, DBEntity:NSManagedObject & ImportableUniqueObject> { ... } ```
adam added the question label 2025-12-29 15:29:17 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jun 3, 2020):

@IdoRabin I'm sorry, did you have any question or was there something not working for you?
If you were asking how to do this, you'll have to declare:

extension ImportableUniqueObject where Self: Identifiable {
    var id: UniqueIDType: {
        return self.uniqueIDValue
    }
}

somewhere in your codebase.

@JohnEstropia commented on GitHub (Jun 3, 2020): @IdoRabin I'm sorry, did you have any question or was there something not working for you? If you were asking how to do this, you'll have to declare: ```swift extension ImportableUniqueObject where Self: Identifiable { var id: UniqueIDType: { return self.uniqueIDValue } } ``` somewhere in your codebase.
Author
Owner

@JohnEstropia commented on GitHub (Jun 3, 2020):

Also to add, CoreStore intentionally does not implement Identifiable by default as it is a use-case dependent semantic.

For example, you are free to use multiple properties as the ID:

class Person: NSManagedObject: Identifiable {
    @NSManaged var firstName: String
    @NSManaged var lastName: String
    // ...

    struct ID: Hashable {
        var firstName: String
        var lastName: String
    }

    var id: ID {
        return ID(firstName: self.firstName, lastName: self.lastName)
    }
}
@JohnEstropia commented on GitHub (Jun 3, 2020): Also to add, CoreStore intentionally does not implement `Identifiable` by default as it is a use-case dependent semantic. For example, you are free to use multiple properties as the ID: ```swift class Person: NSManagedObject: Identifiable { @NSManaged var firstName: String @NSManaged var lastName: String // ... struct ID: Hashable { var firstName: String var lastName: String } var id: ID { return ID(firstName: self.firstName, lastName: self.lastName) } } ```
Author
Owner

@IdoRabin commented on GitHub (Sep 25, 2020):

thanks.

@IdoRabin commented on GitHub (Sep 25, 2020): thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#331