SwiftForms is a small and lightweight library written in Swift that allows you to easily create forms.

Overview

Version Carthage compatible

License Platform

SwiftForms

Purpose

SwiftForms is a powerful and extremely flexible library written in Swift that allows to create forms by just defining them in a couple of lines. It also provides the ability to customize cells appearance, use custom cells and define your own selector controllers.

Here is an screenshot from an example application using SwiftForms

Screenshot of Example application

How to create a form

Creating a form using SwiftForms is pretty straightforward. All you need is to derive your controller from FormViewController and define a FormDescriptor instance along with its sections and rows. Here is an example of how to create a simple form to input an email and a user password.

// Create form instace
var form = FormDescriptor()
form.title = "Example form"

// Define first section
var section1 = FormSectionDescriptor()

var row = FormRowDescriptor(tag: "name", rowType: .Email, title: "Email")
section1.rows.append(row)

row = FormRowDescriptor(tag: "pass", rowType: .Password, title: "Password")
section1.rows.append(row)

// Define second section
var section2 = FormSectionDescriptor()

row = FormRowDescriptor(tag: "button", rowType: .Button, title: "Submit")
section2.rows.append(row)

form.sections = [section1, section2]

self.form = form

To see a more complex form definition you can take a look to the example application.

Cell appearance

Every row descriptor has a configuration dictionary that allows to customize cell's appearance and behavior. In order to change concrete visual aspects of a row simply set row.configuration.cell.appearance value to a dictionary containing custom key-value coding properties.

Here's an example:

row.configuration.cell.appearance = ["titleLabel.font" : UIFont.boldSystemFontOfSize(30.0), "segmentedControl.tintColor" : UIColor.redColor()]

Custom cells

In addition, it is possible to create 100% custom cells by deriving from FormBaseCell class. In that case, don't forget to override configure and update methods. First method will be called only once and after cell has been created, and the second one every time cell content should be refreshed.

Here are the methods that help you to define custom cell behavior.

func configure() {
    /// override
}

func update() {
    /// override
}

class func formRowCellHeight() -> CGFloat {
    return 44.0
}

class func formViewController(formViewController: FormViewController, didSelectRow: FormBaseCell) {
}

Once you have defined your custom cell, and in order to use it for a concrete row, you'll have to set FormRowDescriptor cellClass property.

Custom selector controllers

In order to customize selector controller your class should conform to FormSelector protocol. That way you'll have access to the cell instance that pushed the controller, being able to alter its properties or setting it's row value accordingly to user interaction.

After defining your class, don't forget to set row.configuration.selection.controllerClass value in the configuration dictionary to use your custom selector controller.

Requirements

  • iOS 8.0 and above

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate SwiftForms into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'SwiftForms'

Then, run the following command:

$ pod install

Carthage

Simply add the following line to your Cartfile:

github "ortuman/SwiftForms"

Then run:

$ carthage update

For more information on Carthage see the README

Copyright

SwiftForms is originally based on XLForm github project. (https://github.com/xmartlabs/XLForm)

Check LICENSE file for more details.

Contact

If you are using SwiftForms in your project and have any suggestion or question:

Miguel Angel Ortuño, [email protected]

@ortuman

Comments
  • Swift4 version crash

    Swift4 version crash

    I compiled and ran your example, and all appeared to work.

    Though, I continued to crash when running my loadform(), receiving exceptions. On closer inspection, I click on your project file in Xcode 9 beta3, and notice the Swift Language version was set to "unspecified". Though, I click each SwiftFormsApplication and SwiftForms targets and note these were set to use Swift4.

    With the above setting, I then compile and see compile warnings and runtime errors. See images below. Note the error on line 136 of FormViewController.swift.

    THis is the exact same place where I experience a crash when running in my application. Specifically if I set a cell.appearance, like:

        let row2 = FormRowDescriptor(tag: Static.subtitleTag, type: .text, title: "Subtitle")
        row2.configuration.cell.appearance = ["textField.placeholder" : "Classification" as AnyObject,
                                             "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject]
    

    Then, I will receive a crash on the line 136.

    Appears there is something new in Swift4 regarding key/value changes which was not present in Swift 3.

    Would appreciate any assistance. I can send you my modified project if you would like to take a look.

    pic1 pic2

    opened by appsird 16
  • Add Carthage support

    Add Carthage support

    This pull request enables Carthage support by creating a shared scheme. It also updates the README to reflect Carthage support and adds a Carthage compatible badge to the README. If this PR is accepted a new tagged release needs to be added before Carthage can be used to build the framework.

    opened by rjsamson 7
  • How to use programmatically with custom init?

    How to use programmatically with custom init?

    I need to pass a value on init, and instantiate the FormViewController subclass in code.

    I have this in my subclass:

    init(UUID: String) { super.init(nibName: nil, bundle: nil); self.UUID = UUID self.loadForm() }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    

    It calls the custom init, but I get this error:

    assertion failed: self.form property MUST be assigned!: file /Users/ransom/jobs/sendcontact/sendcontact-ios/SwiftForms/SwiftForms/Source/controllers/FormViewController.swift, line 62

    Is use of a storyboard required? Is there some other super.init i can call?

    If I call super.init(syle: .Grouped) I get this error:

    fatal error: use of unimplemented initializer 'init(nibName:bundle:)' for class 'SendContact.CardFormController'

    opened by ransomweaver 6
  • Cannot enter more than one character in a password field

    Cannot enter more than one character in a password field

    Rows with .Password as RowType cannot handle more than one character. I have tested this on an iPhone 5, iPad retina and the simulator. I have not found a way to fix/circumvent this bug.

    Tested on Xcode 6.1.1 and Yosemite 10.10.1; using SDK 8.1 on iOS 8.1.2

    opened by vrwim 6
  • How to set picker value?

    How to set picker value?

    Hey, could you please tell me if there is a way to set a picker value to one of its options? If the picker itself were exposed I could use something like 'picker.selectRow', but I don't see it? Thank you!

    opened by mgerlach-klick 5
  • Swift 2.0 Conversion

    Swift 2.0 Conversion

    Bare minimal to compile in swift 2.0 and remove and associated warnings from var to let as per the new code analyzer.

    Disregard if you've done this and decline it, but I needed this for myself and wanted the chance to see if it helps you.

    opened by mitchins 4
  • Unwrapping optional error.

    Unwrapping optional error.

    I just tried to use Swift Forms on a tableview without a navigation controller, and I got this error. Maybe we need to check for the UINavigationItem, before unwrapping the optional. screen shot 2014-11-14 at 1 01 46 pm

    opened by JamalK 4
  • new Xcode 9.2 warnings

    new Xcode 9.2 warnings

    When recompiling my project under the latest Xcode 9.2 beta (9C34B) I receive numerous warnings from code within SwiftForms of the attached form.

    'characters' is deprecated: Please us String or Substring directly

    untitled

    My understanding this release will go production soon.

    Would appreciate an update which removes the warnings.

    Thanks again so much for a great form framework, I really appreciate your efforts.

    opened by appsird 3
  • Use Legacy Swift Language Version

    Use Legacy Swift Language Version

    “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

    opened by jorgeefrazaocosta 3
  • FormDescriptor#validateForm not public

    FormDescriptor#validateForm not public

    FormDescriptor#validateForm is not public.

    There does not seem to be a built-in way to validate fields based on FormRowDescriptor.Configuration.Required.

    Is this intentional?

    // SwiftForms/descriptors/FormDescriptor.swift
    
    func validateForm() -> FormRowDescriptor! {
        for section in sections {
            for row in section.rows {
                if let required = row.configuration[FormRowDescriptor.Configuration.Required] as? Bool {
                    if required && row.value == nil {
                        return row
                    }
                }
            }
        }
        return nil
    }
    
    opened by angeloashmore 3
  • How can I make the picker disappear?

    How can I make the picker disappear?

    How can I make the picker disappear when tapping elswhere on the screen? (i.e. outside any other formcells)

    usually something like:

    `override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    
                self.view.endEditing(true)
    
            }`
    

    works, but I don't know where to put it to get it work... Any ideas?

    btw: this is a great piece of coding! Thanks for sharing!

    THX! Kinzi

    opened by Kinzi 3
  • custom cell error

    custom cell error

    when i custom the cell, i implement the class FormBaseCell and override the function configure() and update(), also a variable named myImage as type UIImageView was defined in it. However, it raises an error "this class is not key value coding-compliant for the key myImage." while setting the property 'myImage' in FormViewController class using 'row.configuration.cell.appearance = ["myImage.image": UIImage(named: "Photo") as AnyObject]'. What should i do ?

    opened by Raphael95 0
  • Picker format

    Picker format

    I'm configuring the picker with array values like this:

    `row = FormRowDescriptor(tag: Static.picker, rowType: .Picker, title: "Value") row.configuration[FormRowDescriptor.Configuration.Options] = array.count row.configuration[FormRowDescriptor.Configuration.TitleFormatterClosure] = { value in

    var stringArray = String for index in 0...self.array.count { // append index with cast it to string stringArray.append(String(index)) } return stringArray } as TitleFormatterClosure`

    however I get an error "Cannot convert return expression of type '[String]' to return type 'String!'" Why does this happen?

    opened by corbrink 0
  • Crash when setting font in cell appearance

    Crash when setting font in cell appearance

    Crash in FormViewController line 136 (SwiftForms to 1.8.2 version, Xcode 10 and swift 4.2)

    The only way for me to keep working with SwiftForm: remove the 'titleLabel.font' key from row.configuration.cell.appearance = ["textField.placeholder" : "Mandatory" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject, "titleLabel.font": UIFont.boldSystemFont(ofSize: 15.0)] I don't have the font I'd like but it works!

    opened by abanet 1
  • 'automaticDimension' has been renamed to 'UITableViewAutomaticDimension'

    'automaticDimension' has been renamed to 'UITableViewAutomaticDimension'

    Hi there,

    I'm here to report a matter :

    The upload class "FormSection" from pod install got these lines :

    public var headerViewHeight: CGFloat = UITableView.automaticDimension
     public var footerViewHeight: CGFloat = UITableView.automaticDimension
    

    Which have to be replaced by

    public var headerViewHeight: CGFloat = UITableViewAutomaticDimension
    public var footerViewHeight: CGFloat = UITableViewAutomaticDimension
    

    As the correction take three sec with "unlock" and replace it with the proposal, i guess that no report of this problem have been made (or I didn't seen the topic, by bad if so) But it could be great if this could be add on the pod package =)

    Have a nice day and thanks a lot !

    opened by royalcheese71 1
Releases(1.8.2)
Owner
Miguel Ángel Ortuño
Miguel Ángel Ortuño
SwiftyFORM is a lightweight iOS framework for creating forms

SwiftyFORM is a lightweight iOS framework for creating forms Because form code is hard to write, hard to read, hard to reason about. Has a

Simon Strandgaard 1.1k Dec 29, 2022
SherlockForms - An elegant SwiftUI Form builder to create a searchable Settings and DebugMenu screens for iOS

??️‍♂️ SherlockForms What one man can invent Settings UI, another can discover i

Yasuhiro Inami 98 Dec 27, 2022
Easily validate your Properties with Property Wrappers 👮

ValidatedPropertyKit enables you to easily validate your properties with the power of Property Wrappers. struct LoginView: View { @Validated(

Sven Tiigi 873 Dec 22, 2022
Declarative data validation framework, written in Swift

Peppermint Introduction Requirements Installation Swift Package Manager Usage Examples Predicates Constraints Predicate Constraint Compound Constraint

iOS NSAgora 43 Nov 22, 2022
Carbon🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

A declarative library for building component-based user interfaces in UITableView and UICollectionView. Declarative Component-Based Non-Destructive Pr

Ryo Aoyama 1.2k Jan 5, 2023
Former is a fully customizable Swift library for easy creating UITableView based form.

Former is a fully customizable Swift library for easy creating UITableView based form. Submitting Issues Click HERE to get started with filing a bug r

Ryo Aoyama 1.3k Dec 27, 2022
A rule-based validation library for Swift

SwiftValidator Swift Validator is a rule-based validation library for Swift. Core Concepts UITextField + [Rule] + (and optional error UILabel) go into

null 1.4k Dec 29, 2022
ObjectForm - a simple yet powerful library to build form for your class models.

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

jakehao 175 Nov 2, 2022
iOS Validation Library

Honour Validation library for iOS inspired by Respect/Validation. Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR") ❗ If you w

Jean Pimentel 55 Jun 3, 2021
The most flexible and powerful way to build a form on iOS

The most flexible and powerful way to build a form on iOS. Form came out from our need to have a form that could share logic between our iOS apps and

HyperRedink 32 Aug 15, 2022
A framework to validate inputs of text fields and text views in a convenient way.

FormValidatorSwift The FormValidatorSwift framework allows you to validate inputs of text fields and text views in a convenient way. It has been devel

ustwo™ 500 Nov 29, 2022
Discover new programming concepts and more new SwiftUI 2 features in this section

Africa-Zoo One thing is sure, we will discover new programming concepts and more new SwiftUI 2 features in this section. TOPICS ARE COVERED: JSON with

Noye Samuel 2 Nov 8, 2022
Elegant iOS form builder in Swift

Made with ❤️ by XMARTLABS. This is the re-creation of XLForm in Swift. 简体中文 Overview Contents Requirements Usage How to create a Form Getting row valu

xmartlabs 11.6k Jan 1, 2023
Custom-TopBarController - A Custom TopBar Controller With Swift

TopBarController Верстка Для IPhone и IPod вертска адаптивная, для IPad frane To

Fadeev Sergey 1 Aug 2, 2022
GrouponHeader - iOS TableView Header Animation, Swift/UIKit

GrouponHeader Description: iOS TableView Header Animation Technology: Swift, UIK

James Sedlacek 8 Dec 15, 2022
AtomicReferenceCell - Atomic Reference Cell (Arc) for Swift

Atomic Reference Cell This project provide two structures: Arc<T> and WeakArc<T>

cjw 0 Jan 30, 2022
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.

XLForm By XMARTLABS. If you are working in Swift then you should have a look at Eureka, a complete re-design of XLForm in Swift and with more features

xmartlabs 5.8k Jan 6, 2023
SwiftyFORM is a lightweight iOS framework for creating forms

SwiftyFORM is a lightweight iOS framework for creating forms Because form code is hard to write, hard to read, hard to reason about. Has a

Simon Strandgaard 1.1k Dec 29, 2022
The Bitwarden mobile application is written in C# with Xamarin Android, Xamarin iOS, and Xamarin Forms.

Bitwarden Mobile Application The Bitwarden mobile application is written in C# with Xamarin Android, Xamarin iOS, and Xamarin Forms. Build/Run Require

Bitwarden 4.2k Dec 29, 2022
OONI Probe is free and open source software designed to measure internet censorship and other forms of network interference.

OONI Probe iOS OONI Probe is free and open source software designed to measure internet censorship and other forms of network interference. Click here

Open Observatory of Network Interference (OONI) 59 Nov 2, 2022