Skip to content

daspoon/storable

Repository files navigation

Overview

This project explores the potential of creating CoreData object models from Swift code by applying macros to class and property declarations. It aims to provide an alternative to Xcode's object model editor which:

  • unifies specification of object model and custom logic as Swift code;
  • enables composition of object models;
  • makes property metadata available for tasks such as data import and export;
  • simplifies support for non-standard attribute types.

This project is a work in progress and must be built with the development snapshot toolchain. As Swift macros are an experimental feature, this system cannot be used directly to build applications for distribution on the App Store.

Core Types

The primary codebase is split into two targets: Storable and StorableMacros. The latter is a dynamic library containing macro definitions as currently required by Swift's macro system.

ManagedObject is a subclass of NSManagedObject which serves as the abstract base class for entity definitions.

Storable is the protocol which specifies the requirements of supported attribute types.

ManagedPropertyMacro is a protocol describing the requirements of accessor macros used to define managed object properties; AttributeMacro, RelationshipMacro, and FetchedMacro are the conforming implementations which define descriptors for attributes, relationships and fetched properties. Attribute, Relationship and Fetched are custom descriptor types corresponding to the three subclasses of NSPropertyDescription; each is accompanied by a same-named macro declaration which identifies the corresponding macro implementation type.

EntityMacro is a member macro used to aggregate the managed properties of an associated ManagedObject class. The Entity type is a custom entity descriptor corresponding to NSEntityDescription.

Schema is a structure which represents a complete object model and which generates an NSManagedObjectModel.

DataStore is a convenience class which manages a persistent store and provides an NSManagedObjectContext for a given Schema.

Documentation

An introductory article describes the core mechanics of the system.

A secondary article describes the impact on persistent store migration.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages