Skip to content

Guide · Open source

How to use Eureka: build iOS forms in Swift

Updated · written with AI from the project's own documentation and checked against our catalogue data

Eureka is an MIT-licensed Swift library for iOS that builds forms, such as settings or data-entry screens, on top of UITableView. It is a Swift re-creation of XLForm. This guide shows you how to set up a form controller, add sections and rows, read values and use callbacks, so you can build a working form screen.

Eurekaxmartlabs/Eureka · ★ 11.8k · MIT

Quick start

  1. 1Confirm your project meets the requirements. Make sure you have Xcode 11 or newer and target Swift 5.0 or newer in an iOS project that uses UIKit.
  2. 2Add Eureka to your project. The README says the install method is a package manager and shows a git clone command for the repository. Check the README installation section for the package manager setup your project needs.
  3. 3Subclass FormViewController. Create a view controller that extends FormViewController and import Eureka.
  4. 4Build sections and rows. In viewDidLoad, add sections with +++ and rows with <<<, passing a title and placeholder to each row.
  5. 5Read values. Use form.rowBy(tag:) for a single row or form.values() for all tagged rows.
  6. 6Add behaviour with callbacks. Use onChange() and cellUpdate to respond to user input and change the appearance of rows.

Check the requirements before you start

The README lists Xcode 11+ and Swift 5.0+ as requirements for the latest release. Eureka is described as an iOS library, so it is meant for iOS app projects.

The README describes a UITableView-based approach. If your project is SwiftUI-only, Eureka is not the right fit.

  • Xcode 11 or newer
  • Swift 5.0 or newer
  • An iOS app project

Create a form by extending FormViewController

Extend FormViewController, then add sections and rows to the form variable. The README example creates two sections with a TextRow, a PhoneRow and a DateRow.

You can also set up the form property yourself without subclassing FormViewController, but the README says this method is typically more convenient.

import Eureka class MyFormViewController: FormViewController { override func viewDidLoad() { super.viewDidLoad() form +++ Section("Section1") <<< TextRow(){ row in row.title = "Text Row" row.placeholder = "Enter text here" } <<< PhoneRow(){ $0.title = "Phone Row" $0.placeholder = "And numbers here" } +++ Section("Section2") <<< DateRow(){ $0.title = "Date Row" $0.value = Date(timeIntervalSinceReferenceDate: 0) } } }

Add sections and rows with operators

Eureka provides custom operators. +++ adds a section, <<< inserts a row into the current section, and += appends an array of sections or rows. If you use +++ with a row, Eureka creates a blank section for it, and <<< with no section implicitly creates one.

The README also offers result builders, @SectionBuilder and @FormBuilder, as an alternative syntax that supports if/else inside the form.

  • +++ adds a section
  • <<< inserts a row
  • += appends an array of sections or rows
form +++ Section("First Section") +++ Section("Another Section") form +++ Section() <<< TextRow() <<< DateRow() form += [Section("A"), Section("B"), Section("C")]

Read row values and configure navigation

Each Row holds a value of a specific type. A SwitchRow holds a Bool and a TextRow holds a String. To read one row, look it up by its tag with form.rowBy(tag:). To read all tagged rows at once, call form.values(), which returns a dictionary of tag and value pairs.

The keyboard navigation accessory is controlled by the navigationOptions property on FormViewController. Its default is enabled and skipCanNotBecomeFirstResponderRow. The README also documents animateScroll and rowKeyboardSpacing for scrolling behaviour.

  • navigationOptions: disabled, enabled, stopDisabledRow, skipCanNotBecomeFirstResponderRow
  • animateScroll: enables smooth scrolling to off-screen rows
  • rowKeyboardSpacing: sets space between the keyboard and the highlighted row
let row: TextRow? = form.rowBy(tag: "MyRowTag") let value = row.value let valuesDictionary = form.values()

React to changes with callbacks

Callbacks change how a row looks and behaves. onChange() runs when a row's value changes, and you can use it to adjust other rows or show and hide them. cellSetup and cellUpdate customise the underlying UITableViewCell. The README also notes that onCellSelection() fires for disabled rows too, so check the row's state inside it.

The Eureka README also covers validations, dynamically hiding and showing rows or sections, list sections, multivalued sections and swipe actions. Read the linked sections of the full README for those.

  • onChange(): runs when the value changes
  • cellSetup and cellUpdate: customise the cell
  • onCellSelection(): runs on tap, including for disabled rows

What people use it for

  • A settings screen with switches, text fields and date pickers
  • A data-entry screen with phone number and other typed inputs
  • Showing or hiding fields based on another field's value
  • Migrating an existing XLForm-based app to Swift

Frequently asked questions

How do I install Eureka?

The README lists a package-manager install method and shows a git clone command for the repository. Check the installation section of the README for the full setup steps for your package manager.

What are the requirements for Eureka?

The README lists Xcode 11+ and Swift 5.0+ for the latest release. Eureka targets iOS.

Is Eureka free to use?

Eureka is released under the MIT licence, as shown in the repository. Check the LICENSE file for the full terms.

Does Eureka work with SwiftUI?

The README describes a UITableView-based approach. For SwiftUI-only projects, this source does not suggest Eureka is a good fit.

What is Eureka a re-creation of?

The README says Eureka is a re-creation of XLForm in Swift. Comparable projects listed for this item include XLForm, Form by Dwight Ehrenkrantz and FormKit.

Is Eureka still maintained?

The analysis notes the last push shown is 2024-09-12 and the latest release is 5.5.0, so check recent activity before adopting it for a long-lived project.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Eureka suits iOS developers who build form-heavy UIKit screens in Swift, especially teams moving an XLForm app to Swift. Pick something else if your project is SwiftUI-only, targets non-iOS platforms, or needs a library with very recent maintenance.

Install options & downloads