Model2App: Turn your Swift data model into a working CRUD app.

CI Status Platform iOS Version Carthage License: MIT Twitter: @karolkulesza

Model2App is a simple library that lets you quickly generate a CRUD iOS app based on just a data model defined in Swift. (CRUD – Create Read Update Delete). Ever wanted to quickly validate a data model for your next awesome iOS app? Model2App lets you save hours/days by generating a fully working app with persistence layer, validation and many more features. Just define your model, hit ⌘ + R and enjoy your app.
😎

Model2App uses Realm
❤️
under the hood and can be treated as its extension in development activities, especially in the phase of defining or validating a data model for a bigger project.


🔷
Features


✴️
Automatically generate:

     
✅
App menu based on a list of classes defined by your app
     
✅
Objects list views, per each model class
     
✅
Dynamic object view for creating, updating and viewing objects of a given class, based on list of model properties
     
✅
Object property cells, based either on property type or on declared control type (see supported control types below)
     
✅
Logic to handle different control types to change the values of object properties
     
✅
Validation logic for creating/updating objects using set of predefined rules or custom one using a closure
     
✅
Logic for persisting created objects in local storage (Realm)
     
✅
Logic for invoking object update session and deleting objects
     
✅
Logic for setting relationships between objects, in case of Object properties
     
✅
Related objects’ sections for objects which are referenced by other objects (inverse relationships)
     
✅
Logic for creating a related object from a given object view
     
✅
Logic to traverse (infinitely) between related objects
     
✅
Out of the box zoom-in & zoom-out navigation animations
     
✅
& a bunch of many more small features


✴️
Customize default app configuration:

     
✅
Adjust app menu (layout, order, background, menu items’ icons/layout/alphas, font names/sizes/colors, animations and more)
     
✅
Pick any menu item icon from provided bundle (MenuIcons), provide your own, or let Model2App pick one for you
     
✅
Adjust objects list views (cell layout/background, displayed object properties, images layout, animations and more)
     
✅
Adjust object view property cells (cell layout/background, font names/sizes/colors, images layout, placeholders and more)
     
✅
Adjust object view Related Objects’ headers (header layout/background, font names/sizes/colors)
     
✅
Adjust picker list views (cell layout/background, font names/sizes/colors)
     
✅
Hide a specific class from app menu or hide a specific property of a given class from object view
     
✅
Adjust default animation configuration: presentation/dismissal animation duration, damping ratio or initial spring velocity
     
✅
Specify whether image views presented in cells should be rounded or not


✴️
Other features:

     
✅
Supports both iPhones and iPads
     
✅
Supports both portrait and landscape orientations
     
✅
Validates your data model for declared relationships and declared control types for properties
     
✅
Enables using emoji character for menu icon image
     
✅
Flexibility & Extensibility: Apart from configuration parameters defined in M2AConfig class which can be overridden, most of the classes & methods used for core app features have open access modifier, so you can customize or extend selected parts of Model2App framework in your app


✴️
Supported control types:

     
✏️
TextField
     
✏️
NumberField
     
✏️
FloatDecimalField
     
✏️
DoubleDecimalField
     
✏️
CurrencyField
     
✏️
PhoneField
     
✏️
EmailField
     
✏️
PasswordField
     
✏️
URLField
     
✏️
ZIPField
     
✏️
Switch
     
✏️
DatePicker
     
✏️
TimePicker
     
✏️
DateTimePicker
     
✏️
TextPicker
     
✏️
ObjectPicker
     
✏️
ImagePicker


🔷
Requirements

     
✅
Xcode 10.1+
     
✅
Swift 4.2+


🔷
Installation

Model2App is available through both CocoaPods and Carthage.


✴️
CocoaPods

In order to install Model2App via CocoaPods, simply add the following line to your Podfile:

pod 'Model2App'

Then run the following command:

$ pod install


✴️
Carthage

In order to install Model2App via Carthage, simply add the following line to your Cartfile:

0.1.0
“>

github "Q-Mobile/Model2App" ~> 0.1.0

Then run the following command:

$ carthage update

Please remember to add all *.framework files from Carthage/Build/* to your project (Not only Model2App.framework), apart from other standard steps for Carthage


🔷
Usage


✴️
Model definition:

After installing Model2App, simply define your data model by subclassing ModelClass, as in example below or as in example app available in this repo (Model2AppTestApp) and hit ⌘ + R. (NOTE: Sample data model visible below is just a small excerpt from the example app, please refer to Model2AppTestApp source for a more extended model)

<div class="highlight highlight-source-swift position-relative" data-snippet-clipboard-copy-content="@objcMembers class Company : ModelClass {
dynamic var name : String?
dynamic var phoneNumber : String?
dynamic var industry : String?
}

@objcMembers class Person : ModelClass {
dynamic var firstName : String?
dynamic var lastName : String?
dynamic var salutation : String?
dynamic var phoneNumber : String?
dynamic var privateEmail : String?
dynamic var workEmail : String?
let isKeyOpinionLeader = OptionalProperty()
dynamic var birthday : Date?
dynamic var website : String?
dynamic var note : String?
dynamic var picture : Data?
dynamic var company : Company?
}

@objcMembers class Deal : ModelClass {
dynamic var name : String?
let value = OptionalProperty()
dynamic var stage : String?
dynamic var closingDate : Date?
dynamic var company : Company?
}
“>

@objcMembers class Company : ModelClass {
    dynamic var name : String?
    dynamic var phoneNumber : String?
    dynamic var industry : String?
}

@objcMembers class Person : ModelClass {
    dynamic var firstName : String?
    dynamic var lastName : String?
    dynamic var salutation : String?
    dynamic var phoneNumber : String?
    dynamic var privateEmail : String?
    dynamic var workEmail : String?
    let isKeyOpinionLeader = OptionalProperty<Bool>()
    dynamic var birthday : Date?
    dynamic var website : String?
    dynamic var note : String?
    dynamic var picture : Data?
    dynamic var company : Company?
}

@objcMembers class Deal : ModelClass {
    dynamic var name : String?
    let value = OptionalProperty<Int>()
    dynamic var stage : String?
    dynamic var closingDate : Date?
    dynamic var company : Company?
}