ObjectForm
A simple yet powerful library to build form for your class models.
Motivations
I found most form libraries for swift are too complicated to bootstrap a simple project. So I write ObjectForm to make it dead simple for building forms and binding model classes.
ObjectForm doesn't fight with you to write UIKit code. By design, it is simple to understand and extend. If you follow the example project carefully, you would find it easy to fit in your Swift project.
This project has no dependency of any other library.
Features
- Bind class model to form rows
- Automatic keyboards types according to model types
- Form rows are type safe
- Fully customizable form validation rules
- A list of built-in UITableViewCell to support multiple types
- Work amazingly well with your UITableView code
Requirements
- iOS >= 13.0
Usage
- Copy sources
- Copy files under /Sources into your project.
- Carthage (Coming soon)
- Swift Package Manager
- Click "Files -> Swift Package Manager -> Add Package Dependency..." in Xcode's menu
- Search "https://github.com/haojianzong/ObjectForm".
- Select "master" branch or input "Next major version"
Available Rows & Cells
Rows
StringRow
: Row to support string input, full keyboardDoubleRow
: Row to support number input, numeric keyboardDateRow
: Row to bind Date value
Cells
TextViewInputCell
: text input cellSelectInputCell
: support selection, provided byCollectionPicker
TextViewVC
: A view controller with UITextView to input long textButtonCell
: Show a button in the formTypedInputCell
: Generic cell to support type bindingFormInputCell
: The base class for all cells
Tutorials
You can follow ObjectFormExample in ObjectFormExample
to learn how to build a simple form with a class model.
Binding Model to Form
Showing FormDataSource in a UITableView
Listening to Cell Value Change
Data Validation
By providing a validation block when building a row, you can provide any validaiton rules.
Row Type Safety
Since a form row use key-value-coding to update its bind model, it is important to keep the row value type the same as the object's variable type. ObjectForm enforces type safe. Every row must implement the following method:
override func isValueMatchRowType(value: Any) -> Bool
This is already implemented by built-in generic rows, for example, TypedRow<T>
and SelectRow<T>
.
Make Your Own Row
Making your own row and cell is easy. You have 2 options:
- Create concrete type using
TypedRow
- Subclass
BaseRow