{"id":2826,"url":"https://github.com/venmo/Static","last_synced_at":"2025-08-06T13:32:47.484Z","repository":{"id":34287814,"uuid":"38176891","full_name":"venmo/Static","owner":"venmo","description":"Simple static table views for iOS in Swift.","archived":false,"fork":false,"pushed_at":"2021-10-22T18:21:03.000Z","size":538,"stargazers_count":1253,"open_issues_count":19,"forks_count":87,"subscribers_count":45,"default_branch":"master","last_synced_at":"2024-11-19T20:48:27.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://blog.soff.es/static","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/venmo.png","metadata":{"files":{"readme":"Readme.markdown","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}},"created_at":"2015-06-27T22:00:38.000Z","updated_at":"2024-10-21T05:43:49.000Z","dependencies_parsed_at":"2022-09-14T03:30:45.779Z","dependency_job_id":null,"html_url":"https://github.com/venmo/Static","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venmo%2FStatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venmo%2FStatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venmo%2FStatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venmo%2FStatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/venmo","download_url":"https://codeload.github.com/venmo/Static/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905503,"owners_count":17989778,"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":[],"created_at":"2024-01-05T20:16:23.858Z","updated_at":"2024-12-09T14:31:02.722Z","avatar_url":"https://github.com/venmo.png","language":"Swift","readme":"![Static Logo](docs/static.png)\n\n[![Version](https://img.shields.io/github/release/venmo/Static.svg)](https://github.com/venmo/Static/releases) ![Status](https://travis-ci.org/venmo/Static.svg?branch=master) ![Swift Version](https://img.shields.io/badge/swift-4.2-orange.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nSimple static table views for iOS in Swift. Static's goal is to separate model data from presentation. `Row`s and `Section`s are your “view models” for your cells. You simply specify a cell class to use and that handles all of the presentation. See the [usage](#usage) section below for details.\n\n\n## Version Compatibility\n\n| Swift Version | Static Version |\n| ------------- | -------------- |\n| 5.0+          | 4.0.2          |\n| 4.2+          | 3.0.1          |\n| 3.2+          | 2.1            |\n| 3.0.1         | 2.0.1          |\n| 3.0           | 2.0            |\n| 2.3           | 1.2            |\n| 2.2           | 1.1            |\n| 2.0 - 2.1     | 1.0            |\n\n\n## Installation\n\n### Carthage\n\n[Carthage](https://github.com/carthage/carthage) is the recommended way to install Static. Add the following to your Cartfile:\n\n``` ruby\ngithub \"venmo/Static\"\n```\n\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. To install Static with CocoaPods:\n\nMake sure CocoaPods is installed (Static requires version 0.37 or greater).\n\nUpdate your Podfile to include the following:\n\n```ruby\nuse_frameworks!\npod 'Static', git: 'https://github.com/venmo/Static'\n```\n\nRun `pod install`.\n\n\n### Manual\n\nFor manual installation, it's recommended to add the project as a subproject to your project or workspace and adding the appropriate framework as a target dependency.\n\n\n## Usage\n\nAn [example app](Example) is included demonstrating Static's functionality.\n\n\n### Getting Started\n\nTo use Static, you need to define [`Row`s](Static/Row.swift) and [`Section`s](Static/Section.swift) to describe your data. Here's a simple example:\n\n```swift\nimport Static\n\nSection(rows: [\n    Row(text: \"Hello\")\n])\n```\n\nYou can configure `Section`s and `Row`s for anything you want. Here's another example:\n\n```swift\nSection(header: \"Money\", rows: [\n    Row(text: \"Balance\", detailText: \"$12.00\", accessory: .disclosureIndicator, selection: {\n        // Show statement\n    }),\n    Row(text: \"Transfer to Bank…\", cellClass: ButtonCell.self, selection: {\n        [unowned self] in\n        let viewController = ViewController()\n        self.presentViewController(viewController, animated: true, completion: nil)\n    })\n], footer: \"Transfers usually arrive within 1-3 business days.\")\n```\n\nSince this is Swift, we can provide instance methods instead of inline blocks for selections. This makes things really nice. You don't have to switch on index paths in a `tableView:didSelectRowAtIndexPath:` any more!\n\n\n### Customizing Appearance\n\nThe `Row` never has access to the cell. This is by design. The `Row` shouldn't care about its appearance other than specifying what will handle it. In practice, this has been really nice. Our cells have one responsibility.\n\nThere are several custom cells provided:\n\n* `Value1Cell` — This is the default cell. It's a plain `UITableViewCell` with the `.Value1` style.\n* `Value2Cell` — Plain `UITableViewCell` with the `.Value2` style.\n* `SubtitleCell` — Plain `UITableViewCell` with the `.Subtitle` style.\n* `ButtonCell` — Plain `UITableViewCell` with the `.Default` style. The `textLabel`'s `textColor` is set to the cell's `tintColor`.\n\nAll of these conform to [`Cell`](Static/Cell.swift). The gist of the protocol is one method:\n\n```swift\nfunc configure(row row: Row)\n```\n\nThis gets called by [`DataSource`](Static/DataSource.swift) (which we'll look at more in a minute) to set the row on the cell. There is a default implementation provided by the protocol that simply sets the `Row`'s `text` on the cell's `textLabel`, etc. If you need to do custom things, this is a great place to hook in.\n\n`Row` also has a `context` property. You can put whatever you want in here that the cell needs to know. You should try to use this as sparingly as possible.\n\n\n### Custom Row Accessories\n\n`Row` has an `accessory` property that is an `Accessory` enum. This has cases for all of `UITableViewCellAccessoryType`. Here's a row with a checkmark:\n\n```swift\nRow(text: \"Buy milk\", accessory: .checkmark)\n```\n\nEasy enough. Some of the system accessory types are selectable (like that little *i* button with a circle around it). You can make those and handle the selection like this:\n\n```swift\nRow(text: \"Sam Soffes\", accessory: .detailButton({\n  // Show info about this contact\n}))\n```\n\nAgain, you could use whatever function here. Instance methods are great for this.\n\nThere is an additional case called `.view` that takes a custom view. Here's a `Row` with a custom accessory view:\n\n```swift\nRow(text: \"My Profile\", accessory: .view(someEditButton))\n```\n\n\n### Custom Section Header \u0026 Footer Views\n\n`Section` has properties for `header` and `footer`. These take a `Section.Extremity`. This is an enum with `Title` and `View` cases. `Extremity` is `StringLiteralConvertible` you can simply specify strings if you want titles like we did the [Getting Started](#getting-started) section.\n\nFor a custom view, you can simply specify the `View` case:\n\n```swift\nSection(header: .view(yourView))\n```\n\nThe height returned to the table view will be the view's `bounds.height` so be sure it's already sized properly.\n\n\n### Working with the Data Source\n\nTo hook up your `Section`s and `Row`s to a table view, simply initialize a `DataSource`:\n\n```swift\nlet dataSource = DataSource()\ndataSource.sections = [\n    Section(rows: [\n        Row(text: \"Hello\")\n    ])\n]\n```\n\nNow assign your table view:\n\n```swift\ndataSource.tableView = tableView\n```\n\nEasy as that! If you modify your data source later, it will automatically update the table view for you. It is important that you don't change the table view's `dataSource` or `delegate`. The `DataSource` needs to be those so it can handle events correctly. The purpose of `Static` is to abstract all of that away from you.\n\n\n### Wrapping Up\n\nThere is a provided [`TableViewController`](Static/TableViewController.swift) that sets up a `DataSource` for you. Here's a short example:\n\n```swift\nclass SomeViewController: TableViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        dataSource.sections = [\n            Section(rows: [\n                Row(text: \"Hi\")\n            ]),\n            // ...\n        ]\n    }\n}\n```\n\nEnjoy.\n","funding_links":[],"categories":["UI","Libs","Uncategorized","Swift","Layout [🔝](#readme)"],"sub_categories":["Table View / Collection View","Layout","Uncategorized","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvenmo%2FStatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvenmo%2FStatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvenmo%2FStatic/lists"}