{"id":18736804,"url":"https://github.com/zoul/typed-forms","last_synced_at":"2025-04-12T19:31:55.787Z","repository":{"id":66898362,"uuid":"137729001","full_name":"zoul/typed-forms","owner":"zoul","description":"An experimental typed form library for iOS","archived":true,"fork":false,"pushed_at":"2018-10-11T07:24:03.000Z","size":54,"stargazers_count":2,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T00:34:45.189Z","etag":null,"topics":["forms","swift","uitableview","well-typed"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-18T08:46:32.000Z","updated_at":"2024-07-17T17:38:35.000Z","dependencies_parsed_at":"2023-02-20T22:00:17.291Z","dependency_job_id":null,"html_url":"https://github.com/zoul/typed-forms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoul%2Ftyped-forms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoul%2Ftyped-forms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoul%2Ftyped-forms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoul%2Ftyped-forms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoul","download_url":"https://codeload.github.com/zoul/typed-forms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621156,"owners_count":21134763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forms","swift","uitableview","well-typed"],"created_at":"2024-11-07T15:22:35.312Z","updated_at":"2025-04-12T19:31:55.777Z","avatar_url":"https://github.com/zoul.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"Tables are often used to build forms on iOS, but the `UITableView` API is fairly low-level, offering a plenty of rope to hang yourself. This library attempts to think of a better, high-level API for building type-safe(r) forms using tables.\n\nThe key idea is splitting the particular form logic into a standalone view model type that handles just the logic, and then using simple, declarative rules to build the table cells from that model:\n\n```\n//\n// The view model\n//\n\nstruct Card: Equatable, CustomStringConvertible {\n\n    let name: String\n    let currencies: [String]\n\n    var description: String {\n        return name\n    }\n}\n\n\nstruct ViewModel {\n\n    var cards: [Card]\n    var selectedCard: Card {\n        didSet {\n            selectedCurrency = selectedCard.currencies.first!\n        }\n    }\n\n    var selectedCurrency: String\n    var specifyAmount: Bool\n    var amount: String?\n\n    var canBeSubmitted: Bool {\n        guard specifyAmount else { return true }\n        guard let amount = amount else { return false }\n        return Double(amount) != nil\n    }\n}\n\n//\n// Sample data\n//\n\nlet card1 = Card(name: \"Card #1\", currencies: [\"CZK\", \"EUR\"])\nlet card2 = Card(name: \"Card #2\", currencies: [\"EUR\", \"PLN\", \"GBP\"])\nlet card3 = Card(name: \"Card #3\", currencies: [\"EUR\"])\nlet model = ViewModel(\n    cards: [card1, card2, card3], selectedCard: card2,\n    selectedCurrency: \"EUR\", specifyAmount: false, amount: \"1000\")\n\n//\n// Now let’s build a form from that\n//\n\nlet form = Form\u003cViewModel\u003e()\n\nform += SelectableSection(\"Cards\", items: \\.cards, selectedItem: \\.selectedCard)\n\nform += Section(\"Currency\")\n    \u003c\u003c\u003c FormSegmentedCell(items: \\.selectedCard.currencies, selectedItem: \\.selectedCurrency)\n\nform += Section()\n    \u003c\u003c\u003c FormSwitchCell(keyPath: \\.specifyAmount, title: \"Specify Amount\")\n    \u003c\u003c\u003c FormTextFieldCell(keyPath: \\.amount) {\n        $0.textField.placeholder = \"Enter amount\"\n        $0.textField.clearButtonMode = .whileEditing\n        $0.bind(\\.isHidden, to: \\.specifyAmount, through: { !$0 })\n    }\n\nform += Section()\n    \u003c\u003c\u003c FormButtonCell(title: \"Pay\") {\n        $0.bind(\\.shouldHighlight, to: \\.canBeSubmitted)\n    }\n}\n```\n\nThe `form` object can then be used as a table view data source. The table form is always in sync with the model, there’s no need to manually update the table after model changes or vice versa.\n\n## Related Work / Inspiration\n\n* [Eureka](https://github.com/xmartlabs/Eureka/), a full-featured form building library. Very powerful, but unfortunately not very type safe.\n* [Swift Talks: Building a Form Library](https://talk.objc.io/collections/building-a-form-library), great ideas about building modern, type-safe form library.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoul%2Ftyped-forms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoul%2Ftyped-forms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoul%2Ftyped-forms/lists"}