Skip to content

Conversation

@ChrisLaganiere
Copy link
Owner

@ChrisLaganiere ChrisLaganiere commented Feb 8, 2025

Here's a big takeaway I had from Avi Tsadok's "Unleash Core Data":

We can actually remove all the "Entity+CoreDataProperties.swift" generated code files in an app by using Category/Extension option for code generation in the data model gui tool. Nice!! That was always a big frustration for me, so I love reducing the duplication to just one source of truth.

If you use Manual/None option on code generation, like I always have, you are required to have +CoreDataProperties.swift files, which are generated manually by the developer in Xcode and are redundant and always have to kept in sync with the data model itself when making any changes. You would always have to remember to make any change to the an entity's properties twice:

  1. In the xcdatamodel gui tool
  2. Again, in the associated Entity+CoreDataProperties.swift file

No more! I'm adopting Tsadok's suggestion and using Category/Extension option instead, and deleting the properties files, which will instead be generated at compile time by Xcode in derived data. This effectively automates some work I was doing manually previously.

Doing this also fixed a couple types in the example app! so as a result I'm also changing the framework utils that the example app uses a bit to match the different types (supporting optionals for the CD String properties created in the gui)

Screenshot 2025-02-08 at 1 01 35 PM

Also taking the opportunity to polish example app and readme a little

@ChrisLaganiere ChrisLaganiere changed the title Reduce code needed by using category/extension code generation Learnings from "Unleash Core Data" part 1 Feb 8, 2025
@ChrisLaganiere ChrisLaganiere merged commit 42117b6 into main Feb 9, 2025
1 check passed
@ChrisLaganiere ChrisLaganiere deleted the claganiere/category-code-extension branch February 9, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants