home.social

#coredata — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #coredata, aggregated by home.social.

fetched live
  1. I always wondered why body is called twice in a View using @ObservedObject that is init by .sheet or .alert to edit a newly inserted NSManagedObject. Turns out the context asynchronously sends objectWillChange for all inserted objects despite no properties being changed. #SwiftUI #CoreData

    github.com/feedback-assistant/

  2. I always wondered why body is called twice in a View using @ObservedObject that is init by .sheet or .alert to edit a newly inserted NSManagedObject. Turns out the context asynchronously sends objectWillChange for all inserted objects despite no properties being changed. #SwiftUI #CoreData

    github.com/feedback-assistant/

  3. I always wondered why body is called twice in a View using @ObservedObject that is init by .sheet or .alert to edit a newly inserted NSManagedObject. Turns out the context asynchronously sends objectWillChange for all inserted objects despite no properties being changed. #SwiftUI #CoreData

    github.com/feedback-assistant/

  4. I always wondered why body is called twice in a View using @ObservedObject that is init by .sheet or .alert to edit a newly inserted NSManagedObject. Turns out the context asynchronously sends objectWillChange for all inserted objects despite no properties being changed. #SwiftUI #CoreData

    github.com/feedback-assistant/

  5. Hours wasted in figuring out another #SwiftUI #CoreData design flaw

    Turns out after all these years, NSManagedObject does not implement ObservableObject's objectWillChange contract correctly.

    FB24036828: NSManagedObject objectWillChange states it is emitted before the object changes when in reality it is emitted after it changes

    github.com/feedback-assistant/

  6. Hours wasted in figuring out another #SwiftUI #CoreData design flaw

    Turns out after all these years, NSManagedObject does not implement ObservableObject's objectWillChange contract correctly.

    FB24036828: NSManagedObject objectWillChange states it is emitted before the object changes when in reality it is emitted after it changes

    github.com/feedback-assistant/

  7. Hours wasted in figuring out another #SwiftUI #CoreData design flaw

    Turns out after all these years, NSManagedObject does not implement ObservableObject's objectWillChange contract correctly.

    FB24036828: NSManagedObject objectWillChange states it is emitted before the object changes when in reality it is emitted after it changes

    github.com/feedback-assistant/

  8. Hours wasted in figuring out another #SwiftUI #CoreData design flaw

    Turns out after all these years, NSManagedObject does not implement ObservableObject's objectWillChange contract correctly.

    FB24036828: NSManagedObject objectWillChange states it is emitted before the object changes when in reality it is emitted after it changes

    github.com/feedback-assistant/

  9. #buildInPublic #CoreData #swiftTesting

    To satisfy myself that XCode doesn't touch the generated xxx+CoreDataClass.swift file if it exists, when regenerating the properties file, I made a small change and tried it. In the process I added the Swift testing file as a target, which made all my tests fail in strange ways.

    back to regularly scheduled programming…

    18/n

  10. #buildInPublic #CoreData #swiftTesting

    To satisfy myself that XCode doesn't touch the generated xxx+CoreDataClass.swift file if it exists, when regenerating the properties file, I made a small change and tried it. In the process I added the Swift testing file as a target, which made all my tests fail in strange ways.

    back to regularly scheduled programming…

    18/n

  11. #buildInPublic #CoreData #swiftTesting

    To satisfy myself that XCode doesn't touch the generated xxx+CoreDataClass.swift file if it exists, when regenerating the properties file, I made a small change and tried it. In the process I added the Swift testing file as a target, which made all my tests fail in strange ways.

    back to regularly scheduled programming…

    18/n

  12. #buildInPublic #CoreData #swiftTesting

    Since my inheritance tree for the DTOs maps 1:1 onto the CoreData managed objects, I'd like to inherit the class methods in the subclasses TDMTune and TDMTuneSet, e.g. in TDMTuneSet
    class func makeInstance(from abcObj: AbcTuneSet, context: NSManagedObjectContext) -> TDMTuneSet

    Unfortunately Swift doesn’t allow overriding base-class methods in an extension, so I have to modify the generated TDMxxx+CoreDataClass.swift
    17/n

  13. #buildInPublic #CoreData #swiftTesting

    Since my inheritance tree for the DTOs maps 1:1 onto the CoreData managed objects, I'd like to inherit the class methods in the subclasses TDMTune and TDMTuneSet, e.g. in TDMTuneSet
    class func makeInstance(from abcObj: AbcTuneSet, context: NSManagedObjectContext) -> TDMTuneSet

    Unfortunately Swift doesn’t allow overriding base-class methods in an extension, so I have to modify the generated TDMxxx+CoreDataClass.swift
    17/n

  14. #buildInPublic #CoreData #swiftTesting

    Since my inheritance tree for the DTOs maps 1:1 onto the CoreData managed objects, I'd like to inherit the class methods in the subclasses TDMTune and TDMTuneSet, e.g. in TDMTuneSet
    class func makeInstance(from abcObj: AbcTuneSet, context: NSManagedObjectContext) -> TDMTuneSet

    Unfortunately Swift doesn’t allow overriding base-class methods in an extension, so I have to modify the generated TDMxxx+CoreDataClass.swift
    17/n

  15. #buildInPublic #CoreData #swiftTesting

    bit of a digression here: from my ObjC CoreData days I've been generating the NSManagedObject class definitions through XCode, then my own related code (in this case for translating back and forth from the DTOs) in a separate file as an objC category, with the generated files untouched.
    I built class methods in the base TDMSearchable class
    class func makeInstance(from abcObj : some AbcCollectable, context :NSManagedObjectContext) -> TDMSearchable
    16/n

  16. #buildInPublic #CoreData #swiftTesting

    bit of a digression here: from my ObjC CoreData days I've been generating the NSManagedObject class definitions through XCode, then my own related code (in this case for translating back and forth from the DTOs) in a separate file as an objC category, with the generated files untouched.
    I built class methods in the base TDMSearchable class
    class func makeInstance(from abcObj : some AbcCollectable, context :NSManagedObjectContext) -> TDMSearchable
    16/n

  17. #buildInPublic #CoreData #swiftTesting

    bit of a digression here: from my ObjC CoreData days I've been generating the NSManagedObject class definitions through XCode, then my own related code (in this case for translating back and forth from the DTOs) in a separate file as an objC category, with the generated files untouched.
    I built class methods in the base TDMSearchable class
    class func makeInstance(from abcObj : some AbcCollectable, context :NSManagedObjectContext) -> TDMSearchable
    16/n

  18. #buildInPublic #CoreData #swiftTesting

    next: Conversion of the DTOs to CoreData objects.
    The current structure of JSON encoding assumes a top-down/denormalized structure for import, but since Tunes <-> TuneSets is many:many and Collectibles <-> Collections is m:m, I'd like a way to avoid re-specifying the containment tree.

    As part of that I'll need to look at how to de-duplicate with respect to existing objects.

    14/n

  19. #buildInPublic #CoreData #swiftTesting

    next: Conversion of the DTOs to CoreData objects.
    The current structure of JSON encoding assumes a top-down/denormalized structure for import, but since Tunes <-> TuneSets is many:many and Collectibles <-> Collections is m:m, I'd like a way to avoid re-specifying the containment tree.

    As part of that I'll need to look at how to de-duplicate with respect to existing objects.

    14/n

  20. #buildInPublic #CoreData #swiftTesting

    next: Conversion of the DTOs to CoreData objects.
    The current structure of JSON encoding assumes a top-down/denormalized structure for import, but since Tunes <-> TuneSets is many:many and Collectibles <-> Collections is m:m, I'd like a way to avoid re-specifying the containment tree.

    As part of that I'll need to look at how to de-duplicate with respect to existing objects.

    14/n

  21. #buildInPublic #CoreData #swiftTesting

    ready to push to GitHub again. The DTOs are in the main project but only being exercised from the playground. Time to implement transferring from the DTO to the CoreData store.

    (edit to put the GitHub link in)

    github.com/Wil-Macaulay/attrib

    13/n

  22. #buildInPublic #CoreData #swiftTesting

    ready to push to GitHub again. The DTOs are in the main project but only being exercised from the playground. Time to implement transferring from the DTO to the CoreData store.

    (edit to put the GitHub link in)

    github.com/Wil-Macaulay/attrib

    13/n

  23. #buildInPublic #CoreData #swiftTesting

    ready to push to GitHub again. The DTOs are in the main project but only being exercised from the playground. Time to implement transferring from the DTO to the CoreData store.

    (edit to put the GitHub link in)

    github.com/Wil-Macaulay/attrib

    13/n

  24. #buildInPublic #CoreData #swiftTesting

    I found a few similar ways of doing this using enum with associated type

    medium.com/@ankuriosdev/master

    caseyliss.com/2023/2/2/decodin

    This one from @paulio87 seems the most straightforward to me:

    paul-samuels.com/blog/2019/01/

    it doesn’t require the domain DTOs (in this case AbcTune and AbcTuneSet) to have an explicit 'type’ field, but brings that out to a container.

    (12/n)

  25. #buildInPublic #CoreData #swiftTesting

    I found a few similar ways of doing this using enum with associated type

    medium.com/@ankuriosdev/master

    caseyliss.com/2023/2/2/decodin

    This one from @paulio87 seems the most straightforward to me:

    paul-samuels.com/blog/2019/01/

    it doesn’t require the domain DTOs (in this case AbcTune and AbcTuneSet) to have an explicit 'type’ field, but brings that out to a container.

    (12/n)

  26. #buildInPublic #CoreData #swiftTesting

    I found a few similar ways of doing this using enum with associated type

    medium.com/@ankuriosdev/master

    caseyliss.com/2023/2/2/decodin

    This one from @paulio87 seems the most straightforward to me:

    paul-samuels.com/blog/2019/01/

    it doesn’t require the domain DTOs (in this case AbcTune and AbcTuneSet) to have an explicit 'type’ field, but brings that out to a container.

    (12/n)

  27. #buildInPublic #CoreData #swiftTesting

    (got distracted by other stuff, including wiring up a gazebo and playing tunes. Back at it now…)

    I want to be able to allow the user to have an arbitrary Collection of Tunes and Sets in any order, so I’ll need an Array of Collectables [AbcCollectable]. Now I really am going to need to distinguish between a Tune and a TuneSet at runtime. (11/n)

  28. #buildInPublic #CoreData #swiftTesting

    (got distracted by other stuff, including wiring up a gazebo and playing tunes. Back at it now…)

    I want to be able to allow the user to have an arbitrary Collection of Tunes and Sets in any order, so I’ll need an Array of Collectables [AbcCollectable]. Now I really am going to need to distinguish between a Tune and a TuneSet at runtime. (11/n)

  29. #buildInPublic #CoreData #swiftTesting

    (got distracted by other stuff, including wiring up a gazebo and playing tunes. Back at it now…)

    I want to be able to allow the user to have an arbitrary Collection of Tunes and Sets in any order, so I’ll need an Array of Collectables [AbcCollectable]. Now I really am going to need to distinguish between a Tune and a TuneSet at runtime. (11/n)

  30. #buildInPublic #CoreData #swiftTesting

    I can't inherit CodingKeys, but I _can_ inherit init(from decoder) as well as superclass properties.

    so I've implemented AbcCollectable as a superclass of AbcTune and AbcTuneSet, mirroring the TDMTune and TDMTuneSet relationships. (pushed to the GitHub repo for anyone who’s following along.

    Next I want to implement AbcCollection as a container for _both_ AbcTunes and AbcTuneSets

    (10/n)

  31. #buildInPublic #CoreData #swiftTesting

    I can't inherit CodingKeys, but I _can_ inherit init(from decoder) as well as superclass properties.

    so I've implemented AbcCollectable as a superclass of AbcTune and AbcTuneSet, mirroring the TDMTune and TDMTuneSet relationships. (pushed to the GitHub repo for anyone who’s following along.

    Next I want to implement AbcCollection as a container for _both_ AbcTunes and AbcTuneSets

    (10/n)

  32. #buildInPublic #CoreData #swiftTesting

    I can't inherit CodingKeys, but I _can_ inherit init(from decoder) as well as superclass properties.

    so I've implemented AbcCollectable as a superclass of AbcTune and AbcTuneSet, mirroring the TDMTune and TDMTuneSet relationships. (pushed to the GitHub repo for anyone who’s following along.

    Next I want to implement AbcCollection as a container for _both_ AbcTunes and AbcTuneSets

    (10/n)

  33. #buildInPublic #CoreData #swiftTesting

    Looks like I can't inherit CodingKeys from a superclass, I have to redefine them in any subclass that adds properties. Yet another example of the Swift language designers wagging their collective fingers at inheritance vs composition…

    (9/n)

  34. #buildInPublic #CoreData #swiftTesting

    Looks like I can't inherit CodingKeys from a superclass, I have to redefine them in any subclass that adds properties. Yet another example of the Swift language designers wagging their collective fingers at inheritance vs composition…

    (9/n)

  35. #buildInPublic #CoreData #swiftTesting

    Looks like I can't inherit CodingKeys from a superclass, I have to redefine them in any subclass that adds properties. Yet another example of the Swift language designers wagging their collective fingers at inheritance vs composition…

    (9/n)

  36. #buildInPublic #CoreData #swiftTesting

    A slight wrinkle: a Collection can contain both Tunes and TuneSets, in arbitrary order. In our CoreData model, we handle this by having a common superclass, Collectable, which has the common attributes and relationships. The ‘obvious' thing to do is have a common DTO superclass AbcCollectible handle basic encoding and decoding with the subclasses doing anything specific - in our trimmed down prototype that means TuneSet handling contained Tunes
    (7/n)

  37. #buildInPublic #CoreData #swiftTesting

    A slight wrinkle: a Collection can contain both Tunes and TuneSets, in arbitrary order. In our CoreData model, we handle this by having a common superclass, Collectable, which has the common attributes and relationships. The ‘obvious' thing to do is have a common DTO superclass AbcCollectible handle basic encoding and decoding with the subclasses doing anything specific - in our trimmed down prototype that means TuneSet handling contained Tunes
    (7/n)

  38. #buildInPublic #CoreData #swiftTesting

    A slight wrinkle: a Collection can contain both Tunes and TuneSets, in arbitrary order. In our CoreData model, we handle this by having a common superclass, Collectable, which has the common attributes and relationships. The ‘obvious' thing to do is have a common DTO superclass AbcCollectible handle basic encoding and decoding with the subclasses doing anything specific - in our trimmed down prototype that means TuneSet handling contained Tunes
    (7/n)

  39. Moving from Core Data to SwiftData? Don't clean up your model on the first pass.

    A practical "room by room" migration strategy showing why matching the legacy SQLite schema exactly is critical. Skip this and your users get a fatal error on launch.

    🔗: emredegirmenci.substack.com/p/ by Emre Degirmenci (@aemre)

    #SwiftData #CoreData #iOSDev

  40. Moving from Core Data to SwiftData? Don't clean up your model on the first pass.

    A practical "room by room" migration strategy showing why matching the legacy SQLite schema exactly is critical. Skip this and your users get a fatal error on launch.

    🔗: emredegirmenci.substack.com/p/ by Emre Degirmenci (@aemre)

    #SwiftData #CoreData #iOSDev

  41. Moving from Core Data to SwiftData? Don't clean up your model on the first pass.

    A practical "room by room" migration strategy showing why matching the legacy SQLite schema exactly is critical. Skip this and your users get a fatal error on launch.

    🔗: emredegirmenci.substack.com/p/ by Emre Degirmenci (@aemre)

    #SwiftData #CoreData #iOSDev

  42. Moving from Core Data to SwiftData? Don't clean up your model on the first pass.

    A practical "room by room" migration strategy showing why matching the legacy SQLite schema exactly is critical. Skip this and your users get a fatal error on launch.

    🔗: emredegirmenci.substack.com/p/ by Emre Degirmenci (@aemre)

    #SwiftData #CoreData #iOSDev

  43. #buildInPublic #CoreData #swiftTesting

    Approach 1 would let us trivially use Decoders to ingest the data files and Encoders to write them, the files will get big fast.
    Approach 2 lets us more easily manually prepare special test cases and is easier to understand. Let's go with approach 2.
    (5/n)

  44. #buildInPublic #CoreData #swiftTesting

    Approach 1 would let us trivially use Decoders to ingest the data files and Encoders to write them, the files will get big fast.
    Approach 2 lets us more easily manually prepare special test cases and is easier to understand. Let's go with approach 2.
    (5/n)

  45. #buildInPublic #CoreData #swiftTesting

    Approach 1 would let us trivially use Decoders to ingest the data files and Encoders to write them, the files will get big fast.
    Approach 2 lets us more easily manually prepare special test cases and is easier to understand. Let's go with approach 2.
    (5/n)

  46. #buildInPublic #CoreData #swiftTesting

    So we're introducing some Data Transfer Objects [DTOs] that can be trivially Codable.

    How do we represent the [m:m] relationships? two choices:
    1. denormalize in the json file, so that we start by ingesting Collections, providing a full copy of each TuneSet and Tune occuring in each Collection then culling out duplicates
    2. introduce an ID attribute for each domain object so that we ingest relationships as an ID to be reconciled after ingestion.
    (4/n)

  47. #buildInPublic #CoreData #swiftTesting

    So we're introducing some Data Transfer Objects [DTOs] that can be trivially Codable.

    How do we represent the [m:m] relationships? two choices:
    1. denormalize in the json file, so that we start by ingesting Collections, providing a full copy of each TuneSet and Tune occuring in each Collection then culling out duplicates
    2. introduce an ID attribute for each domain object so that we ingest relationships as an ID to be reconciled after ingestion.
    (4/n)

  48. #buildInPublic #CoreData #swiftTesting

    So we're introducing some Data Transfer Objects [DTOs] that can be trivially Codable.

    How do we represent the [m:m] relationships? two choices:
    1. denormalize in the json file, so that we start by ingesting Collections, providing a full copy of each TuneSet and Tune occuring in each Collection then culling out duplicates
    2. introduce an ID attribute for each domain object so that we ingest relationships as an ID to be reconciled after ingestion.
    (4/n)

  49. #buildInPublic #CoreData #swiftTesting

    types (that is classes or structs) that are built from Codables can be trivially made codable. Fortunately most of the properties of our domain objects are Codable (Strings and Dates). however, NSManagedObjects are not directly Codable, since you need an NSManagedObjectContext to create an instance.

    There are ways around that, but more importantly we've got [m:m] relationships in our data model which are hard to directly encode/decode. (3/n)

  50. #buildInPublic #CoreData #swiftTesting

    types (that is classes or structs) that are built from Codables can be trivially made codable. Fortunately most of the properties of our domain objects are Codable (Strings and Dates). however, NSManagedObjects are not directly Codable, since you need an NSManagedObjectContext to create an instance.

    There are ways around that, but more importantly we've got [m:m] relationships in our data model which are hard to directly encode/decode. (3/n)

  51. #buildInPublic #CoreData #swiftTesting

    types (that is classes or structs) that are built from Codables can be trivially made codable. Fortunately most of the properties of our domain objects are Codable (Strings and Dates). however, NSManagedObjects are not directly Codable, since you need an NSManagedObjectContext to create an instance.

    There are ways around that, but more importantly we've got [m:m] relationships in our data model which are hard to directly encode/decode. (3/n)