Giter Site home page Giter Site logo

swift-table's Introduction

Swift Table

The fastest and easiest way to present a UITableView - in 3 lines of code.

Powered by Generics to present any data type.

No need to use the UITableViewDelegate and UITableViewDataSource protocols.

Swift Table is a free and open-source library that removes the hundreds of lines of code you need to create a fully-customized TableView.

Image examples of three TableViews

Example:

var table = Table(data: ["Adam", "Juan", "Kate", "Siddharth", "Mary", "Zhao"])
let tableView = table.show()
view.addSubview(tableView)

That is all you need!

Another example:

let table = Table(reuseIdentifier: “id”,
                  data: [“Krishna”, “Thomas”, “Jaimie”, “Susan”],
                  frame: view.frame)
                  {indexPath, element, cell in
                       print(“Tapped on element: \(element))
                        cell.addCheckmark()
              }

let tableView = table.show()

// Customization
table.setHeader(title: “Family!)
table.setAccessory(style: .disclosureIndicator)

Features:

  • Supports single and multiple sections of data
  • Can show a subtitle and image label for each cell
  • Provide your own action triggered when a cell is tapped
  • Over 30 public methods to customize most aspects of TableViews - headers, cellHeight, accessories, fonts, colors and much more
  • Includes support for Documentation Compiler (DocC) to show code documentation and tips as you type
  • Supports Swift Package Manager (SPM) and Cocoapods dependency managers.

Benefits:

  • Reduce the hundreds of lines of codes you use for TableViews
  • Save dozens of hours of development time
  • Prevent confusing errors

Quick tips:

  • If you want to show a TableView with one section, insert one array into the data parameter or call the .setData() method. If you want to show a TableView with multiple sections, insert a multidimensional array into the datasets parameter or call the .setDatasets() method.
  • To perform any changes, try using the public methods on the Table class. For example: table.setCellHeight(54.0) or table.setTitleColor(color: .blue)
  • If your desired change is not in our public methods, try using table.addStyle() - which allows you to customize the TableView and its cells, indexPath and elements directly
  • To present your own custom class or struct, conform to the TableData protocol.
  • Open the Example folder to see an Xcode Project showing how to use Swift Table.
  • Current issue: if a TableView is not shown, make sure the Table variable is a global variable (outside of viewDidLoad or any other function) - for reference, see the Example project.

Installation:

Public methods:

Data:

  • append(element: D)
  • insert(element: D, at index: Int)
  • insert(element: D, at index: Int, datasetIndex: Int)
  • removeElement(at index: Int)
  • removeElement(at index: Int, datasetIndex: Int)
  • randomElement() -> D?
  • setData(data: [D])
  • setDatasets(datasets: [[D]])
  • shuffleElements()
  • removeAllElements()

Appearance:

  • setTitleFont(font: UIFont)
  • setTitleColor(color: UIColor)
  • setSubtitleFont(font: UIFont)
  • setSubtitleColor(color: UIColor)
  • setImageTint(color: UIColor)
  • setImageFrame(frame: CGRect)
  • setImageContentMode(contentMode: UIView.ContentMode)
  • setHeader(title: String)
  • setHeader(titles: [String])
  • setHeaderView(view: UIView)
  • setFooterView(view: UIView)
  • setAccessory(style: UITableViewCell.AccessoryType)
  • setAccessoryColor(color: UIColor)
  • setCellHeight(height: Float)
  • setSeparatorColor(color: UIColor)
  • setSeparatorInset(edgeInsets: UIEdgeInsets)
  • setKeyboardDismiss(mode: UIScrollView.KeyboardDismissMode)
  • setAction(action: @escaping (IndexPath, D, UITableViewCell)
  • setAccessoryAction(action: @escaping (IndexPath, D, UITableViewCell) -> Void)
  • addStyle(style: @escaping (UITableView, IndexPath, D, UITableViewCell) -> Void)
  • clearStyles()

Access TableView:

  • show() -> UITableView
  • hide()
  • setFrame(frame: CGRect)
  • showFrame() -> CGRect

Created by:

Benyam Alemu Sood and Jigyasaa Alemu Sood, 2022.

Swift Table is a free and opensource library distributed under the MIT License. You may use the source code for free in any of our personal and commercial libraries.

If you would like to, you may create any articles, tutorials or videos describing any component of this library.

Swift Table will always be free to use and openly available.

If this project helps you, consider donating! Sponsor us here to support new innovations for iOS Developers

Collaboration:

We are in active development. We welcome collaboration.

Feel free to send any pull requests or proposed changes to our codebase. Submit your ideas and code improvements.

swift-table's People

Contributors

sivx76 avatar daveverwer avatar

Stargazers

夏雾 avatar lichunfei avatar 海了个螺 avatar utku sapaz avatar Slava Volodin avatar  avatar Fazle Rabbi avatar Richard Fairhurst avatar Sandin Dulic avatar Matthias Buchetics avatar SuperY avatar  avatar Faustino Koepp avatar Tim Kersey avatar Hyejee Kim avatar Joohee Kim avatar Vyacheslav Khorkov avatar Roberto Machorro avatar Sean Thomas Burke avatar

Watchers

 avatar  avatar

Forkers

azuredark

swift-table's Issues

Introduce GitHub actions

Why:

  • We want to setup an automated process to make sure our Example project successfully compiles after every change to this library. We want to make sure there are no breaking changes in each pull request and push.

Acceptance criteria:

  • Introduce GitHub actions into this repository to check the main branch and staging branch.
  • Trigger upon each pull request and push.
  • Check if the Swift code in the Xcode Project successfully builds and if the unit tests pass.
  • For now: we don't have unit tests. I added a placeholder testing suite.

Other details:

  • I tried this before to no success. You can probably see a stream of past commits.

Allow Table to be shown as a global variable

Why:

  • Currently, Table can only produce a TableView (using its show method) and add it to the View Hierarchy if it is a global variable. The table can be shown when it is a variable inside of a View Controller but not when Table is a variable inside any other method ie. present in the scope of viewDidLoad() or anywhere else.
  • Current workaround: make sure Table is a global variable and reassign it later OR use setData() or any of the public methods to change its behavior.

Acceptance criteria:

  • Allow the TableView to be shown if the Table variable is created in viewDidLoad.
  • Also test if you can create a Table from any non-lifecycle method you create.
  • Explain why Table had to be a global variable to display it's TableView onto the screen.

Other:

  • Guess: Issue with the Table being removed from memory via ARC?
  • Not sure if it is a reference issue.

Exclude unnecessary files from SPM

Why:

  • When pulling this repo using Swift Package Manager, Xcode will grab ALL the files into the repository including unnecessary ones.
  • We don't want to increase the file size of other projects and add unnecessary clutter.

Acceptance criteria:

  • Modify Package.swift and the exclude parameter to remove all unnecessary files
  • Remove: ["Contributors Guide.rtf", "LICENSE", "Opportunties.rtf", "Tables.podspec", "Example", "Other", ".git", ".gitignore"]

Other:

  • I tried using the exclude parameter but when pulling from SPM, I still see these files in Xcode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.