• Stars
    star
    1,074
  • Rank 43,067 (Top 0.9 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

iOS framework for creating forms

Build Status Version Platform Swift Package Manager Carthage MIT License

SwiftyFORM is a lightweight iOS framework for creating forms

Dark Mode supported

Because form code is hard to write, hard to read, hard to reason about. Has a slow turn around time. Is painful to maintain.

SwiftyFORM demo on YouTube

Requirements

  • iOS 12+
  • Xcode 12+
  • Swift 5.1+

Features

  • Several form items, such as textfield, buttons, sliders
  • Some form items can expand/collapse, such as datepicker, pickerview
  • You can create your own custom form items
  • Align textfields across multiple rows
  • Form validation rule engine
  • Shows with red text where there are problems with validation
  • Strongly Typed
  • Pure Swift
  • No 3rd party dependencies

USAGE

Tutorial 0 - Static text

import SwiftyFORM
class MyViewController: FormViewController {
    override func populate(_ builder: FormBuilder) {
        builder += StaticTextFormItem().title("Hello").value("World")
    }
}

Tutorial 1 - TextField

import SwiftyFORM
class MyViewController: FormViewController {
    override func populate(_ builder: FormBuilder) {
        builder += TextFieldFormItem().title("Email").placeholder("Please specify").keyboardType(.emailAddress)
    }
}

Tutorial 2 - Open child view controller

import SwiftyFORM
class MyViewController: FormViewController {
    override func populate(_ builder: FormBuilder) {
        builder += ViewControllerFormItem().title("Go to view controller").viewController(FirstViewController.self)
    }
}

Advanced - date picker

class DatePickerBindingViewController: FormViewController {
    override func populate(_ builder: FormBuilder) {
        builder += datePicker
        builder += incrementButton
        builder += decrementButton
        builder += SectionFormItem()
        builder += summary
        updateSummary()
    }
    
    lazy var datePicker: DatePickerFormItem = {
        let instance = DatePickerFormItem()
        instance.title = "Date"
        instance.datePickerMode = .date
        instance.behavior = .expandedAlways
        instance.valueDidChangeBlock = { [weak self] _ in
            self?.updateSummary()
        }
        return instance
    }()
    
    lazy var incrementButton: ButtonFormItem = {
        let instance = ButtonFormItem()
        instance.title = "Next Day"
        instance.action = { [weak self] in
            self?.increment()
        }
        return instance
    }()
    
    lazy var decrementButton: ButtonFormItem = {
        let instance = ButtonFormItem()
        instance.title = "Previous Day"
        instance.action = { [weak self] in
            self?.decrement()
        }
        return instance
    }()
    
    lazy var summary: StaticTextFormItem = {
        return StaticTextFormItem().title("Date").value("-")
    }()
    
    func updateSummary() {
        summary.value = "\(datePicker.value)"
    }
    
    func offsetDate(_ date: Date, days: Int) -> Date {
        var dateComponents = DateComponents()
        dateComponents.day = days
        let calendar = Calendar.current
        guard let resultDate = calendar.date(byAdding: dateComponents, to: date) else {
            return date
        }
        return resultDate
    }
    
    func increment() {
        datePicker.setValue(offsetDate(datePicker.value, days: 1), animated: true)
        updateSummary()
    }
    
    func decrement() {
        datePicker.setValue(offsetDate(datePicker.value, days: -1), animated: true)
        updateSummary()
    }
}

Advanced - Validation

Change password form

class ChangePasswordViewController: FormViewController {
    override func populate(_ builder: FormBuilder) {
        builder.navigationTitle = "Password"
        builder += SectionHeaderTitleFormItem().title("Your Old Password")
        builder += passwordOld
        builder += SectionHeaderTitleFormItem().title("Your New Password")
        builder += passwordNew
        builder += passwordNewRepeated
        builder.alignLeft([passwordOld, passwordNew, passwordNewRepeated])
    }
    
    lazy var passwordOld: TextFieldFormItem = {
        let instance = TextFieldFormItem()
        instance.title("Old password").password().placeholder("required")
        instance.keyboardType = .numberPad
        instance.autocorrectionType = .no
        instance.validate(CharacterSetSpecification.decimalDigitCharacterSet(), message: "Must be digits")
        instance.submitValidate(CountSpecification.min(4), message: "Length must be minimum 4 digits")
        instance.validate(CountSpecification.max(6), message: "Length must be maximum 6 digits")
        return instance
        }()
    
    lazy var passwordNew: TextFieldFormItem = {
        let instance = TextFieldFormItem()
        instance.title("New password").password().placeholder("required")
        instance.keyboardType = .numberPad
        instance.autocorrectionType = .no
        instance.validate(CharacterSetSpecification.decimalDigitCharacterSet(), message: "Must be digits")
        instance.submitValidate(CountSpecification.min(4), message: "Length must be minimum 4 digits")
        instance.validate(CountSpecification.max(6), message: "Length must be maximum 6 digits")
        return instance
        }()
    
    lazy var passwordNewRepeated: TextFieldFormItem = {
        let instance = TextFieldFormItem()
        instance.title("Repeat password").password().placeholder("required")
        instance.keyboardType = .numberPad
        instance.autocorrectionType = .no
        instance.validate(CharacterSetSpecification.decimalDigitCharacterSet(), message: "Must be digits")
        instance.submitValidate(CountSpecification.min(4), message: "Length must be minimum 4 digits")
        instance.validate(CountSpecification.max(6), message: "Length must be maximum 6 digits")
        return instance
        }()
}

INSTALLATION

Swift Package Manager

With Swift Package Manager support in the latest Xcode, installation has never been easier.

Open your Xcode project -> File -> Swift Packages -> Add Package Dependency...

Search for SwiftyFORM and specify the version you want. The latest tagged release is usually a good idea.

CocoaPods

To integrate SwiftyFORM into your Xcode project using CocoaPods, specify the following in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
swift_version = '5.0'
platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
    pod 'SwiftyFORM', '~> 1.8'
end

Then, run the following command:

$ pod install

Carthage

Link to demo project that shows a minimal SwiftyFORM app using Carthage.

To integrate SwiftyFORM into your Xcode project using Carthage, specify it in your Cartfile:

github "neoneye/SwiftyFORM" ~> 1.8

Then, run the following command:

$ carthage update

Finally, add SwiftyFORM.framework (will be built by Carthage under Carthage/Build/iOS/) to your project's Linked Frameworks and Libraries in the General tab, and add a new Run Script Build Phase:

  • Set /bin/bash as the shell
  • write /usr/local/bin/carthage copy-frameworks in the script body
  • add $(SRCROOT)/Carthage/Build/iOS/SwiftyFORM.framework to the input files

Manual

  1. Open up Terminal application and cd into your iOS project directory

  2. ONLY IF your project is not already initialized as a git repository, run

$ git init
  1. Add SwiftyFORM as a submodule by running
$ git submodule add https://github.com/neoneye/SwiftyFORM.git
  1. In the Project Navigator, select your application project and go to "Targets" -> "General"

  2. Open the project folder and drag the SwiftyFORM.xcodeproj file into the "Frameworks, Libraries, and Embedded Content" tab of your application.

  3. Click the + button under the "Frameworks, Libraries, and Embedded Content" section and Add the SwiftyFORM.framework

Communication

  • If you want to contribute, submit a pull request.
  • If you found a bug, have suggestions or need help, please, open an issue.
  • If you need help, write me: [email protected]

More Repositories

1

autodescribe

Prints human-readable information about an instance
Objective-C
120
star
2

ARC-Interactive-History-Dataset

The history files when recording human interaction while solving ARC tasks
Python
93
star
3

newton-commander

Dual-pane file manager with tabs for macOS
Objective-C
65
star
4

arc-notes

My writings about ARC (Abstraction and Reasoning Corpus)
57
star
5

SpecificationPattern

Specification pattern implemented in swift (iOS/OSX)
Swift
45
star
6

arc-dataset-collection

Multiple datasets for ARC (Abstraction and Reasoning Corpus)
Python
37
star
7

AnalyzeCopy

Metadata is lost when copying files around. It happens with cp, tar, rsync, Finder, Transmit, PathFinder. etc.
Ruby
24
star
8

ARC-Interactive

Enjoy puzzle-solving directly in your browser.
JavaScript
18
star
9

SwiftSnakeEngine

YOU vs AI, in the classic snake game!
Swift
17
star
10

osxutils

improvements to Sveinbjorn Thordarson osxutils
C
10
star
11

SwiftyRelativePath

Swift equivalent of Ruby's "Pathname.relative_path_from()"
Swift
9
star
12

simon-arc-lab

My experiments with ARC-AGI (Abstraction and Reasoning Corpus)
Python
7
star
13

SSEventFlow

SSEventFlow is a type safe alternative to NotificationCenter, inspired by Flux
Swift
6
star
14

SwiftyServerRouter-Demo

Proof of concept generating documentation for all endpoints
Swift
5
star
15

rubikswift

Rubiks cube experiments
Swift
5
star
16

simon-arc-env

Abstraction and Reasoning Corpus as a Farama Gymnasium environment.
Python
4
star
17

interactive-prime-number-patterns

What does the prime numbers look like?
HTML
4
star
18

arc-prompt

Prompts for solving ARC (Abstraction and Reasoning Corpus) with GPT4 or similar
2
star
19

SwiftySchwartzianTransform

Advanced overkill sort operation for the swift language
Swift
2
star
20

loda-arc-challenge

Abstraction and Reasoning Corpus (ARC) solutions
Assembly
2
star
21

cocoaheads-2013-game0

cocoaheads game in an evening
Objective-C
2
star
22

aeditor

AEditor is a programmers text editor written entirely in Ruby
Ruby
1
star
23

arc-output-size

Predicting the output size of an ARC task (Abstraction and Reasoning Corpus)
1
star
24

arc_baseline

Python
1
star
25

mac_chat_client

Simple chat bot UI for Mac
Swift
1
star
26

loda-outlier-programs

Incorrect LODA programs that diverges after a number of terms
Assembly
1
star
27

neoneye

Config files for my GitHub profile.
1
star
28

loda-patterns

Collection of patterns in LODA programs.
Assembly
1
star
29

arcathon-docker-image

1
star
30

arc-dataset-tama

Big ARC tasks compatible with the Abstraction and Reasoning Corpus json file format
1
star
31

arc-dataset-diva

Tiny ARC tasks compatible with the Abstraction and Reasoning Corpus json file format
1
star
32

neoneye.github.io

Simon Strandgaard's homepage
JavaScript
1
star