Easier way to represent the structure of UITableView.

Overview

Shoyu

Pod Version Pod Platform Pod License Build Status

Shoyu is a library written in Swift to represent UITableView data structures.

Shoyu means Soy Sauce in Japanese.

Usage

Create single section and single row

Use createSection and createRow.

tableView.source = Source() { source in

    // Create section
    source.createSection { section in

        // Create row
        section.createRow { row in

            // Setting reuse identifier
            row.reuseIdentifier = "Cell"

            // Setting fixed height.
            row.height = 52

            // Configuring handler for cell.
            row.configureCell = { cell, _ in
                cell.textLabel?.text = "row 1"
            }
        }
    }
}

if ClassName and ReuseIdentifier specified in Storyboard are the same, you don't need to specify the reuseIdentifier.

Create rows for corresponds to the array

Use createRows.

let members = [
    Member(firstName: "Hamada", lastName: "Hiro"),
    Member(firstName: "Hamada", lastName: "Tadashi"),
    Member(firstName: "Tamago", lastName: "GoGo"),
    Member(firstName: "", lastName: "Wasabi"),
    Member(firstName: "Lemon", lastName: "Honey"),
    Member(firstName: "", lastName: "Fred"),
]

tableView.source = Source() { source in
    source.createSection { section in
        section.createRows(members) { member, row in
            row.height = 52
            row.configureCell = { cell, _ in
                cell.textLabel?.text = member.fullName
            }
        }
    }
}

Create section header and section footer

Use createHeader and createFooter.

tableView.source = Source() { source in
   source.createSection { section in

        // Create header.
        section.createHeader { header in
            // Setting title.
            header.title = "Big Hero 6"

            header.height = 22
            header.configureView = { view, _ in
                view.backgroundColor = UIColor.lightGrayColor()
            }
        }

        // Create footer.
        section.createFooter { footer in
          ...
        }
    }
}

Generics

Section and Row is compatible with generics.

Section

public class Section<HeaderType: UIView, FooterType: UIView>: SectionType {
  ...
}

Row

public class Row<CellType: UITableViewCell>: RowType {
  ...
}

cell in the arguments of configureCell is the type specified in the generics. Section header and section footer are also similar.

// Create generic row.
section.createRows(members) { (member, row: Row<MemberTableViewCell>) in
    row.configureCell = { cell, _ in
        // cell type is MemberTableViewCell.
        cell.nameLabel.text = member.fullName
    }
}

Row's delegate

Row has some delegate methods.

section.createRow { row in

    // Configuring handler for height.
    row.heightFor = { _ -> CGFloat? in
        return 52
    }

    // Configuring handler for cell.
    row.configureCell = { cell, _ in
        cell.textLabel?.text = "row"
    }

    // Event handler for when cell is selected.
    row.didSelect = { _ in
        print("row is selected.")
    }
}

Supported delegate methods

  • configureCell
  • heightFor
  • canRemove
  • canMove
  • canMoveTo
  • didSelect
  • didDeselect
  • willDisplayCell
  • didEndDisplayCell
  • willRemove
  • didRemove

License

Shoyu is released under the MIT license. See LICENSE for details.

Comments
  • Invalid Swift Support

    Invalid Swift Support

    When i upload itunes connect. itunes connect say invalid binary. this is email from itunes connect

    Invalid Swift Support - The file 당근마켓.app/Frameworks/Shoyu.framework doesn’t have the correct file type for this location. Ensure you’re using the correct file, rebuild your app using the current public (GM) version of Xcode, and resubmit it.
    

    i use recent xcode(7.2) and cocoapods(1.0.0 beta2, also has an issue in 0.39.0).

    opened by seapy 3
  • Swift 3

    Swift 3

    Ran it through the migrator. There was much to change. Mostly just publicopen and adding _ to the first argument label in method signatures. I updated the podspec to 0.2.0, as well.

    opened by evandcoleman 1
  • Add: check permit index path

    Add: check permit index path

    Why

    I get out of bounds from Shoyu.Section func rowFor(row: Int) via UITableViewDelegate.didEndDisplayCell. I faced this problem when I write that swift logic.

        class AnyTableViewController: UITableViewController {
    
            var elements: Element = // Elements ...
    
            func setupShoyu() {
            tableView.source = Source().createSection { section in
                section.createRows(elements) { row in
                    ...
                }
            }
    
    
    
            func deleteElement(element: Element) { 
                elements.removeFrom(element) 
                setupShoyu() // Reset source.
                tableView.reloadData()  // Get out of bounds from this statement.
            }
        }
    

    I thought removeElement and reset source then disappear corresponded cell. But Shoyu.Section.rows.count is less than the past. When get Shoyu.Section.row[indexPath.row], it would fall down.

    What

    I add Shoyu.Source.isPermitIndexPath function. This function is check indexPath when didEndDisplayCell. If not permit indexPath when early stage return.

    opened by bannzai 1
  • A form suggestion

    A form suggestion

    [fix] Add create view demo. 6421d42 サンプルにview.backgroundColor = UIColor.orangeColorと書かれていたのにかわっていなかったので付け足してみました。

    [fix] Ordered create view flow. ef65d6b dequeを確認してからviewをつくるという流れがなんとなく自然かなと思いました。 また、viewFor が実装されていると、reuseIdentifierを設定しても通らなくなってしまうので、 処理の順番を入れ替えてみました。

    opened by bannzai 1
  • Configure header or footer height.

    Configure header or footer height.

    Why

    It seems that behavior has changed when UITableView#heightForHeaderInSection behavior return 0 and return tableView.sectionHeaderHeight(-1) when it becomes iOS 11. Also delegate for footer has same problem.

    Problem

    When Using grouped style UITableView

    • Until then(iOS 10.*)
      • When return 0 in heightForHeaderInSection, setting UIKIt/UITableView configured implicity default height(about 20px).
      • When return -1, setting UIKIt/UITableView configured implicity default height(about 20px).
    • iOS 11
      • When return 0 in heightForHeaderInSection, setting truth zero height. (This is different from then)
      • When return -1, setting UIKIt/UITableView configured implicity default height(about 20px).

    When Using plain style UITableView

    • Until then(iOS 10.*)
      • When return 0 in heightForHeaderInSection, setting truth zero height.
      • When return -1, setting ` setting zero height.
    • iOS 11
      • When return 0 in heightForHeaderInSection, setting truth zero height.
      • When return -1, setting UIKIt/UITableView configured implicity default height(about 20px). (This is different from then)

    I faced when using grouped UITableView and not instanciate SectionHeaderFooterType.height(or heightFor(_:section:)). So, using Shoyu return 0 height via UITableView#heightForHeaderInSection delegate method in this case.

    But I confirmed iOS 10.3 simulator and iOS 11 simulator get difference height for header at this time.

    How to resolve

    I guess necessary switch for UITableView.style about returning height for delegate method. Grouped UITableView returning always tableView.sectionHeaderHeight when not configure SectionHeaderFooterType.height(or heightFor(_:section:)).Plain UITableViewreturning always0when not configureSectionHeaderFooterType.height(or heightFor(_:section:)).

    I guess it is necessary switch of UITableView.style about returning height for delegate method Grouped style UITableView return tableView.sectionHeaderHeight when not configure SectionHeaderFooterType.height(or heightFor(_:section:)). Plain style UITableView return always 0 when not configure SectionHeaderFooterType.height(or heightFor(_:section:)).

    Plaase check this issue problem. Thank you.

    opened by bannzai 1
  • Podspec problem

    Podspec problem

    Hey,

    When i just put the library name in the Podfile, it fetchs only 1.0.0 So i need to add the version by tag or by commit even by using ' ~> 1.0' or ' ~> 1.1'

    Don't forget to fix that 👍

    opened by gorbat-o 0
  • Fix crash on update in background

    Fix crash on update in background

    Without this, Row would crash during didEndDisplayCell handling if table view is not on active controller (for example if there's modal controller on top of table view controller).

    The solution here is to simply ignore the call if didEndDisplayCell block is not assigned on Row. This preserves existing functionality for cases where block is used but prevents the crash otherwise.

    Besided crash fix, I also added ability to delete section from source.

    opened by tomaz 0
Releases(1.1.0)
Owner
yukiasai
yukiasai
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 155 May 12, 2022
An iOS drop-in UITableView, UICollectionView and UIScrollView superclass category for showing a customizable floating button on top of it.

MEVFloatingButton An iOS drop-in UITableView, UICollectionView, UIScrollView superclass category for showing a customizable floating button on top of

Manuel Escrig 298 Jul 17, 2022
Automates prefetching of content in UITableView and UICollectionView

Automates preheating (prefetching) of content in UITableView and UICollectionView. Deprecated on iOS 10. This library is similar to UITableViewDataSou

Alexander Grebenyuk 633 Sep 16, 2022
Netflix and App Store like UITableView with UICollectionView, written in pure Swift 4.2

GLTableCollectionView Branch Status master develop What it is GLTableCollectionView is a ready to use UITableViewController with a UICollectionView fo

Giulio 708 Nov 17, 2022
Incremental update tool to UITableView and UICollectionView

EditDistance is one of the incremental update tool for UITableView and UICollectionView. The followings show how this library update UI. They generate

Kazuhiro Hayashi 90 Jun 9, 2022
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.

GenericDataSource A generic small reusable components for data source implementation for UITableView/UICollectionView written in Swift. Features Basic

null 132 Sep 8, 2021
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

A declarative library for building component-based user interfaces in UITableView and UICollectionView. Declarative Component-Based Non-Destructive Pr

Ryo Aoyama 1.2k Jan 5, 2023
💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.

DiffableDataSources ?? A library for backporting UITableView/UICollectionViewDiffableDataSource powered by DifferenceKit. Made with ❤️ by Ryo Aoyama I

Ryo Aoyama 762 Dec 28, 2022
ZHTCView - UITableview & UICollectionView

ZHTCView 这是一个使用Block替换代理的UITableview & UICollectionView。 使用方法如下: - (DSTableView *)tableView { if (!_tableView) { _tableView = DSTableView.

黑酒一 0 Jan 10, 2022
A Swift mixin for reusing views easily and in a type-safe way (UITableViewCells, UICollectionViewCells, custom UIViews, ViewControllers, Storyboards…)

Reusable A Swift mixin to use UITableViewCells, UICollectionViewCells and UIViewControllers in a type-safe way, without the need to manipulate their S

Olivier Halligon 2.9k Jan 3, 2023
Easy way to integrate pagination with dummy views in CollectionView, make Instagram "Discover" within minutes.

AZCollectionView Controller Features Automatic pagination handling No more awkward empty CollectionView screen AZ CollectionVIew controller give you a

Afroz Zaheer 95 May 11, 2022
A guy that helps you manage collections and placeholders in easy way.

Why? As mobile developers we all have to handle displaying collections of data. But is it always as simple as it sounds? Looks like spaghetti? It is a

AppUnite Sp. z o.o. Spk. 47 Nov 19, 2021
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 157 Nov 25, 2022
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 155 May 12, 2022
A way to represent what you’re sharing.

About This project provides a preview of items being shared via UIActivityViewController. Example: // standard activity view controller let vc = UIAct

Ryan Ackermann 759 Nov 24, 2022
Represent and compare versions via semantic versioning (SemVer) in Swift

Version Version is a Swift Library, which enables to represent and compare semantic version numbers. It follows Semantic Versioning 2.0.0. The represe

Marius Rackwitz 175 Nov 29, 2022
HoverConversion realized vertical paging with UITableView. UIViewController will be paged when reaching top or bottom of UITableView contentOffset.

HoverConversion ManiacDev.com referred. https://maniacdev.com/2016/09/hoverconversion-a-swift-ui-component-for-navigating-between-multiple-table-views

Taiki Suzuki 166 Feb 1, 2022
Async State Machine aims to provide a way to structure an application thanks to state machines

Async State Machine Async State Machine aims to provide a way to structure an application thanks to state machines. The goal is to identify the states

Thibault Wittemberg 27 Nov 17, 2022
A simple way to create a UITableView for settings in Swift.

QuickTableViewController A simple way to create a table view for settings, including: Table view cells with UISwitch Table view cells with center alig

Cheng-Yao Lin 525 Dec 20, 2022
A simpler way to do cool UITableView animations! (╯°□°)╯︵ ┻━┻

TableFlip (╯°□°)╯︵ ┻━┻ ┬──┬ ノ( ゜-゜ノ) Animations are cool. UITableView isn't. So why not make animating UITableView cool? The entire API for TableFlip

Joe Fabisevich 555 Dec 9, 2022