Now let's put all of this generated goodness to use. We can use these to perform the most common operations (fetching, insertion, updating, deletion) with various predicates (for filtering, sorting.) on the plain model itself, without interfacing with Core Data at all, as if it's not even there. Let’s start with this simple Swift class with two members, a: String and b: Int, and create a Core Data entity from it.Įxtension SimpleModel: Persistable, UniqueIDConstraintKeyPath Let's take a look at some examples of what CDG can do for us, starting with simple examples and then moving on to more advanced use-cases. Welcome, Core Data Generator (CDG)!īacked by Sourcery, CDG offers automatic generation of Core Data entities, relationships, and various operations (fetching, insertion, updating, deletion, sorting, filtering) from plain Swift models including classes, structs and enums, and even enums with associated values. To add to that, to leverage other Swift goodies such as value types, sum types, etc, we will frequently have to manually write mappings, duplicate models, and glue-code to keep the elegance of working with these Swift constructs while maintaining compatibility with Core Data.īut, let’s automate that. Type-safety in predicates for sorting, filtering, etc.Enums (with or without associated values), unless they conform to RawRepresentable.However, while Core Data is an incredibly powerful framework with a variety of useful features, it is beginning to show its age, especially since Swift became the de facto standard for iOS development.īecause Core Data is an Objective-C framework, we often forget many of the nice features that Swift brought to the table, namely: You have likely used it for anything from simply caching relational (and non-relational) data, to the more advanced capabilities such as complex transaction-based operations. If you are an iOS developer, chances are you are very familiar with Core Data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |