Generates Swift NSManagedObject subclasses

Overview

Build Status

MotoSwift. Managed Objects to Swift.

Generates Swift NSManagedObject subclasses.

Benefits

Why is it better than Xcode generation?

  1. Xcode generates properties ignoring optional flag
  2. Allows to customize generated code with templates
  3. Allows to specify type for transform properties

Why is it better than Mogenerator?

  1. Allows to generate extensions for machine code

Additionally it allows to generate one file for whole model, e.g. you need list of entity names

Installation

  1. Install MotoSwift by downloading MotoSwift.pkg from the latest GitHub release and running it.

  2. From sources.

Clone or download project.

Run make install

If you need all components in one folder run make bundle. Now you can copy whole motoswift folder, and run motoswift/bin/motoswift from any place

Usage

  • motoswift human [OPTIONS] MODEL_PATH - generate human code for your model. Does not overwrite file, if file already exists

    Options:

    • --template - Path to entity template.
    • --file-mask - The file name mask for entity file, e.g: "{{class}}.swift"
    • --output - The output directory
  • motoswift machine [OPTIONS] MODEL_PATH - generate machine code for your model. Overwrites file every time

    Options:

    • --template - Path to entity template.
    • --file-mask - The file name mask for entity file, e.g: "{{class}}+Properties.swift"
    • --output - The output directory
  • motoswift model [OPTIONS] MODEL_PATH - generate code for your model

    Options:

    • --output - Output file path.
    • --template - Path to model template.

Examples

  1. Xcode style

motoswift human --template ./Templates/xcode/class.stencil --output ./SampleOutput/Xcode --file-mask "{{class}}+CoreDataClass.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

motoswift machine --template ./Templates/xcode/properties.stencil --output ./SampleOutput/Xcode --file-mask "{{class}}+CoreDataProperties.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Xcode

  1. Mogenerator style

motoswift human --template ./Templates/mogenerator/human.stencil --output ./SampleOutput/Mogenerator/Human --file-mask "{{class}}.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Mogenerator/Human

motoswift machine --template ./Templates/mogenerator/machine.stencil --output ./SampleOutput/Mogenerator/Machine --file-mask "_{{class}}.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Mogenerator/Machine

  1. All entity and field names

motoswift model --template ./Templates/model.stencil --output ./SampleOutput/Model/Model.swift ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Model/Model.swift

Tests

make test

Releasing

make .package

Additional documentation

MotoSwift uses Stencil as template language

You might also like...
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.
🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.

🎯 PredicateKit PredicateKit is an alternative to NSPredicate allowing you to write expressive and type-safe predicates for CoreData using key-paths,

This project server as a demo for anyone who wishes to learn Core Data in Swift.

CoreDataDemo This project server as a demo for anyone who wishes to learn Core Data in Swift. The purpose of this project is to help someone new to Co

Core functionality for Swift projects

Swift library with our shared code How to install .package(url: "https://github.com/ydataai/swift-core.git", from: "master"), About 👯‍♂️ With ❤️ from

Swift Package for deduplicating entity protocol.

DeDuplicatingEntity DeDuplicatingEntity is a protocol you can add to your Core Data model types to give them the functionality to deduplicate their in

TaskManager-CoreData - Swift IOS Application created primarily to familiarize with the CoreData framework and gain knowledge to work with it
SwiftFM is a Swift framework for the FileMaker Data API

SwiftFM SwiftFM is a Swift framework for the FileMaker Data API (Swift 5.5, iOS 15 required). It utilizes modern Swift features like async/await and i

A small set of utilities to make working with CoreData and Swift a bit easier.

SuperRecord =================== SUPPORTS SWIFT 2.0 from Version = 1.4 ** SUPPORTS SWIFT 1.2 from Version = 1.3 Both iOS and WatchOS A Swift CoreData

A type-safe, fluent Swift library for working with Core Data
A type-safe, fluent Swift library for working with Core Data

Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for working with Core Data in Swift. CDQI tremendously reduces the amount o

Comments
  • Feature/model path

    Feature/model path

    As I am using Sourcery alongside this handy tool, i was missing a few stencil capabilities i got used to there.

    So i updated the Renderer to use StencilSwiftKit. This adds a few new cool filters to be used in the templates.

    Also, i added the modelName to be available in the template as a variable.

    Awesome tool, btw.

    opened by Landsi 4
  • Like Xcode

    Like Xcode

    Hi! Thanks for great tool

    I Use this template for generate code like Xcode.

    // DO NOT EDIT. This file is machine-generated and constantly overwritten.
    // Make changes to {{ file }} instead.
    
    import Foundation
    import CoreData
    
    // swiftlint:disable file_length
    // swiftlint:disable type_body_length
    extension {{ class }} {
       public {% if parent.class %}override {% endif %}class var entityName: String {
          return "{{ name }}"
       }
    
       @nonobjc public class func fetchRequest() -> NSFetchRequest<{{ class }}> {
           return NSFetchRequest<{{ class }}>(entityName: self.entityName)
       }
    
       {% for attribute in attributes %}
       @NSManaged public var {{ attribute.name }}: {% if attribute.isScalar %}{{ attribute.scalarType }}{% else %}{{ attribute.type }}{% if attribute.isOptional %}?{% endif %}{% endif %}
       {% endfor %}
    
       {% for relationship in relationships %}
       {% if not relationship.toMany %}
       @NSManaged public var {{ relationship.name }}: {% if relationship.class %}{{ relationship.class }}{% else %}NSManagedObject{% endif %}{% if relationship.isOptional %}?{% endif %}
       {% else %}
       @NSManaged public var {{ relationship.name }}: {% if relationship.isOrdered %}NSOrderedSet{% else %}NSSet{% endif %}
       {% endif %}
       {% endfor %}
    }
    
    {% for relationship in relationships %}
    {% if relationship.toMany %}
    extension {{ class }} {
    
        @objc(add{{ relationship.name | capitalize }}Object:)
        @NSManaged public func addTo{{ relationship.name | capitalize }}(_ value: {{ relationship.class }})
    
        @objc(remove{{ relationship.name | capitalize }}Object:)
        @NSManaged public func removeFrom{{ relationship.name | capitalize }}(_ value: {{ relationship.class }})
    
        @objc(add{{ relationship.name | capitalize }}:)
        @NSManaged public func addTo{{ relationship.name | capitalize }}(_ values: NSSet)
    
        @objc(remove{{ relationship.name | capitalize }}:)
        @NSManaged public func removeFrom{{ relationship.name | capitalize }}(_ values: NSSet)
    
    }
    {% endif %}
    {% endfor %}
    
    opened by makleso6 2
  • Error: Unexpected attribute type: 'UUID'

    Error: Unexpected attribute type: 'UUID'

    When running against any model that includes fields of type UUID, MotoSwift aborts with Error: Unexpected attribute type: 'UUID'. I am on MotoSwift 0.6.0. Please let me know if you need any other information.

    PS: Thanks for making this, it looks great :)

    opened by INuvanda 0
Releases(0.6.0)
Owner
null
A powerful and elegant Core Data framework for Swift.

A powerful and elegant Core Data framework for Swift. Usage Beta version. New docs soon... Simple do that: let query = persistentContainer.viewContext

null 782 Nov 6, 2022
CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift.

CloudCore CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift. Features Leveraging NSPersist

deeje cooley 123 Dec 31, 2022
Unleashing the real power of Core Data with the elegance and safety of Swift

Unleashing the real power of Core Data with the elegance and safety of Swift Dependency managers Contact Swift 5.4: iOS 11+ / macOS 10.13+ / watchOS 4

John Estropia 3.7k Jan 9, 2023
CoreData based Swift ORM

Swift ORM Features Pure swift objects - no more subclasses of NSManagedObject Extensible attribute system - store any type in CoreData storage by impl

Prisma Labs 89 Dec 29, 2022
Swift client library to interact with Supabase Storage

storage-swift Swift Client library to interact with Supabase Storage.

Supabase 21 Dec 1, 2022
HitList is a Swift App shows the implementation of Core Data.

HitList HitList is a Swift App shows the implementation of Core Data. It is the demo app of Ray Wenderlich's tech blog. For details please reference G

Kushal Shingote 2 Dec 9, 2022
A type-safe, fluent Swift library for working with Core Data

Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for working with Core Data in Swift. CDQI tremendously reduces the amount o

null 31 Oct 26, 2022
JSON to Core Data and back. Swift Core Data Sync.

Notice: Sync was supported from it's creation back in 2014 until March 2021 Moving forward I won't be able to support this project since I'm no longer

Nes 2.5k Dec 31, 2022
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices.

Cadmium is a Core Data framework for Swift that enforces best practices and raises exceptions for common Core Data pitfalls exactly where you make the

Jason Fieldman 123 Oct 18, 2022
100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer

DATAStack helps you to alleviate the Core Data boilerplate. Now you can go to your AppDelegate remove all the Core Data related code and replace it wi

Nes 216 Jan 3, 2023