Skip to content

Commit

Permalink
Updating to Swift3
Browse files Browse the repository at this point in the history
  • Loading branch information
xai3 committed Sep 28, 2016
1 parent 1ac7631 commit 1697dbd
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 359 deletions.
2 changes: 1 addition & 1 deletion Classes/ReuseIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol ReuseIdentifierType {

extension ReuseIdentifierType {
var identifier: String {
return String(self.dynamicType).componentsSeparatedByString(".").last ?? ""
return String(describing: type(of: self)).components(separatedBy: ".").last ?? ""
}
}

Expand Down
64 changes: 32 additions & 32 deletions Classes/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@

import UIKit

public class Row<T: UITableViewCell>: RowType {
public typealias RowInformation = (row: Row<T>, tableView: UITableView, indexPath: NSIndexPath)
public typealias RowMoveInformation = (row: Row<T>, tableView: UITableView, sourceIndexPath: NSIndexPath, destinationIndexPath: NSIndexPath)
open class Row<T: UITableViewCell>: RowType {
public typealias RowInformation = (row: Row<T>, tableView: UITableView, indexPath: IndexPath)
public typealias RowMoveInformation = (row: Row<T>, tableView: UITableView, sourceIndexPath: IndexPath, destinationIndexPath: IndexPath)

public init() { }

public init(@noescape closure: (Row<T> -> Void)) {
public init(closure: ((Row<T>) -> Void)) {
closure(self)
}

public var configureCell: ((T, RowInformation) -> Void)?
public var heightFor: (RowInformation -> CGFloat?)?
public var canRemove: (RowInformation -> Bool)?
public var canMove: (RowInformation -> Bool)?
public var canMoveTo: (RowMoveInformation -> Bool)?
public var didSelect: (RowInformation -> Void)?
public var didDeselect: (RowInformation -> Void)?
public var willDisplayCell: ((T, RowInformation) -> Void)?
public var didEndDisplayCell: ((T, RowInformation) -> Void)?
public var willRemove: (RowInformation -> UITableViewRowAnimation?)?
public var didRemove: (RowInformation -> Void)?

private var _reuseIdentifier: String?
public var reuseIdentifier: String {
open var configureCell: ((T, RowInformation) -> Void)?
open var heightFor: ((RowInformation) -> CGFloat?)?
open var canRemove: ((RowInformation) -> Bool)?
open var canMove: ((RowInformation) -> Bool)?
open var canMoveTo: ((RowMoveInformation) -> Bool)?
open var didSelect: ((RowInformation) -> Void)?
open var didDeselect: ((RowInformation) -> Void)?
open var willDisplayCell: ((T, RowInformation) -> Void)?
open var didEndDisplayCell: ((T, RowInformation) -> Void)?
open var willRemove: ((RowInformation) -> UITableViewRowAnimation?)?
open var didRemove: ((RowInformation) -> Void)?

fileprivate var _reuseIdentifier: String?
open var reuseIdentifier: String {
set {
_reuseIdentifier = newValue
}
Expand All @@ -44,64 +44,64 @@ public class Row<T: UITableViewCell>: RowType {
}
}

public var height: CGFloat?
open var height: CGFloat?
}

extension Row: RowDelegateType {
func configureCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath) {
func configureCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath) {
guard let genericCell = cell as? T else {
fatalError()
}
configureCell?(genericCell, (self, tableView, indexPath))
}

func heightFor(tableView: UITableView, indexPath: NSIndexPath) -> CGFloat? {
func heightFor(_ tableView: UITableView, indexPath: IndexPath) -> CGFloat? {
return heightFor?((self, tableView, indexPath)) ?? height
}

func canEdit(tableView: UITableView, indexPath: NSIndexPath) -> Bool {
func canEdit(_ tableView: UITableView, indexPath: IndexPath) -> Bool {
return canRemove(tableView, indexPath: indexPath) || canMove(tableView, indexPath: indexPath)
}

func canRemove(tableView: UITableView, indexPath: NSIndexPath) -> Bool {
func canRemove(_ tableView: UITableView, indexPath: IndexPath) -> Bool {
return canRemove?((self, tableView, indexPath)) ?? false
}

func canMove(tableView: UITableView, indexPath: NSIndexPath) -> Bool {
func canMove(_ tableView: UITableView, indexPath: IndexPath) -> Bool {
return canMove?((self, tableView, indexPath)) ?? false
}

func canMoveTo(tableView: UITableView, sourceIndexPath: NSIndexPath, destinationIndexPath: NSIndexPath) -> Bool {
func canMoveTo(_ tableView: UITableView, sourceIndexPath: IndexPath, destinationIndexPath: IndexPath) -> Bool {
return canMoveTo?((self, tableView, sourceIndexPath, destinationIndexPath)) ?? false
}

func didSelect(tableView: UITableView, indexPath: NSIndexPath) {
func didSelect(_ tableView: UITableView, indexPath: IndexPath) {
didSelect?((self, tableView, indexPath))
}

func didDeselect(tableView: UITableView, indexPath: NSIndexPath) {
func didDeselect(_ tableView: UITableView, indexPath: IndexPath) {
didDeselect?((self, tableView, indexPath))
}

func willDisplayCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath) {
func willDisplayCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath) {
guard let genericCell = cell as? T else {
fatalError()
}
willDisplayCell?(genericCell, (self, tableView, indexPath))
}

func didEndDisplayCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath) {
func didEndDisplayCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath) {
guard let genericCell = cell as? T else {
fatalError()
}
didEndDisplayCell?(genericCell, (self, tableView, indexPath))
}

func willRemove(tableView: UITableView, indexPath: NSIndexPath) -> UITableViewRowAnimation {
return willRemove?((self, tableView, indexPath)) ?? .Fade
func willRemove(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewRowAnimation {
return willRemove?((self, tableView, indexPath)) ?? .fade
}

func didRemove(tableView: UITableView, indexPath: NSIndexPath) {
func didRemove(_ tableView: UITableView, indexPath: IndexPath) {
didRemove?((self, tableView, indexPath))
}
}
24 changes: 12 additions & 12 deletions Classes/RowType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public protocol RowType {
}

protocol RowDelegateType {
func configureCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath)
func heightFor(tableView: UITableView, indexPath: NSIndexPath) -> CGFloat?
func canEdit(tableView: UITableView, indexPath: NSIndexPath) -> Bool
func canRemove(tableView: UITableView, indexPath: NSIndexPath) -> Bool
func canMove(tableView: UITableView, indexPath: NSIndexPath) -> Bool
func canMoveTo(tableView: UITableView, sourceIndexPath: NSIndexPath, destinationIndexPath: NSIndexPath) -> Bool
func didSelect(tableView: UITableView, indexPath: NSIndexPath)
func didDeselect(tableView: UITableView, indexPath: NSIndexPath)
func willDisplayCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath)
func didEndDisplayCell(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath)
func willRemove(tableView: UITableView, indexPath: NSIndexPath) -> UITableViewRowAnimation
func didRemove(tableView: UITableView, indexPath: NSIndexPath)
func configureCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath)
func heightFor(_ tableView: UITableView, indexPath: IndexPath) -> CGFloat?
func canEdit(_ tableView: UITableView, indexPath: IndexPath) -> Bool
func canRemove(_ tableView: UITableView, indexPath: IndexPath) -> Bool
func canMove(_ tableView: UITableView, indexPath: IndexPath) -> Bool
func canMoveTo(_ tableView: UITableView, sourceIndexPath: IndexPath, destinationIndexPath: IndexPath) -> Bool
func didSelect(_ tableView: UITableView, indexPath: IndexPath)
func didDeselect(_ tableView: UITableView, indexPath: IndexPath)
func willDisplayCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath)
func didEndDisplayCell(_ tableView: UITableView, cell: UITableViewCell, indexPath: IndexPath)
func willRemove(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewRowAnimation
func didRemove(_ tableView: UITableView, indexPath: IndexPath)
}
48 changes: 24 additions & 24 deletions Classes/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,81 @@

import UIKit

public class Section<HeaderType: UIView, FooterType: UIView>: SectionType {
public private(set) var rows: [RowType] = []
open class Section<HeaderType: UIView, FooterType: UIView>: SectionType {
open fileprivate(set) var rows: [RowType] = []

public var header: SectionHeaderFooterType?
public var footer: SectionHeaderFooterType?
open var header: SectionHeaderFooterType?
open var footer: SectionHeaderFooterType?

public init() { }

public init(@noescape closure: (Section<HeaderType, FooterType> -> Void)) {
public init(closure: ((Section<HeaderType, FooterType>) -> Void)) {
closure(self)
}
}

extension Section {
public var rowCount: Int { return rows.count }

public func rowFor(row: Int) -> RowType {
public func rowFor(_ row: Int) -> RowType {
return rows[row]
}

public func rowFor(indexPath: NSIndexPath) -> RowType {
return rowFor(indexPath.row)
public func rowFor(_ indexPath: IndexPath) -> RowType {
return rowFor((indexPath as NSIndexPath).row)
}

public func removeRow(index: Int) -> RowType {
return rows.removeAtIndex(index)
public func removeRow(_ index: Int) -> RowType {
return rows.remove(at: index)
}

public func insertRow(row: RowType, index: Int) {
rows.insert(row, atIndex: index)
public func insertRow(_ row: RowType, index: Int) {
rows.insert(row, at: index)
}
}

extension Section {
public func addRow(row: RowType) -> Self {
public func add(row: RowType) -> Self {
rows.append(row)
return self
}

public func addRows(rows: [RowType]) -> Self {
self.rows.appendContentsOf(rows)
public func add(rows: [RowType]) -> Self {
self.rows.append(contentsOf: rows)
return self
}

public func createRow<T>(@noescape closure: (Row<T> -> Void)) -> Self {
return addRow(Row<T>() { closure($0) })
public func createRow<T>(_ closure: ((Row<T>) -> Void)) -> Self {
return add(row: Row<T>() { closure($0) })
}

public func createRows<T, E>(elements: [E], @noescape closure: ((E, Row<T>) -> Void)) -> Self {
return addRows(
public func createRows<T, E>(for elements: [E], closure: ((E, Row<T>) -> Void)) -> Self {
return add(rows:
elements.map { element -> Row<T> in
return Row<T>() { closure(element, $0) }
}.map { $0 as RowType }
)
}

public func createRows<T>(count: UInt, @noescape closure: ((UInt, Row<T>) -> Void)) -> Self {
return createRows([UInt](0..<count), closure: closure)
public func createRows<T>(for count: UInt, closure: ((UInt, Row<T>) -> Void)) -> Self {
return createRows(for: [UInt](0..<count), closure: closure)
}

public func createHeader(@noescape closure: (SectionHeaderFooter<HeaderType> -> Void)) -> Self {
public func createHeader(_ closure: ((SectionHeaderFooter<HeaderType>) -> Void)) -> Self {
return createHeaderFooter { (header: SectionHeaderFooter<HeaderType>) in
self.header = header
closure(header)
}
}

public func createFooter(@noescape closure: (SectionHeaderFooter<FooterType> -> Void)) -> Self {
public func createFooter(_ closure: ((SectionHeaderFooter<FooterType>) -> Void)) -> Self {
return createHeaderFooter { (footer: SectionHeaderFooter<FooterType>) in
self.footer = footer
closure(footer)
}
}

private func createHeaderFooter<T>(@noescape closure:(SectionHeaderFooter<T> -> Void)) -> Self {
fileprivate func createHeaderFooter<T>(_ closure: ((SectionHeaderFooter<T>) -> Void)) -> Self {
closure(SectionHeaderFooter<T>())
return self
}
Expand Down
28 changes: 14 additions & 14 deletions Classes/SectionHeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

import UIKit

public class SectionHeaderFooter<Type: UIView>: SectionHeaderFooterType {
open class SectionHeaderFooter<Type: UIView>: SectionHeaderFooterType {
public typealias SectionHeaderFooterInformation = (headerFooter: SectionHeaderFooter<Type>, tableView: UITableView, section: Int)

public init() { }

public init(@noescape closure: (SectionHeaderFooter<Type> -> Void)) {
public init(closure: ((SectionHeaderFooter<Type>) -> Void)) {
closure(self)
}

private var _reuseIdentifier: String?
public var reuseIdentifier: String? {
fileprivate var _reuseIdentifier: String?
open var reuseIdentifier: String? {
set {
_reuseIdentifier = newValue
}
Expand All @@ -33,32 +33,32 @@ public class SectionHeaderFooter<Type: UIView>: SectionHeaderFooterType {
}
}

public var height: CGFloat?
public var title: String?
open var height: CGFloat?
open var title: String?

public var configureView: ((Type, SectionHeaderFooterInformation) -> Void)?
public var heightFor: (SectionHeaderFooterInformation -> CGFloat?)?
public var titleFor: (SectionHeaderFooterInformation -> String?)?
public var createView: (SectionHeaderFooterInformation -> Type?)?
open var configureView: ((Type, SectionHeaderFooterInformation) -> Void)?
open var heightFor: ((SectionHeaderFooterInformation) -> CGFloat?)?
open var titleFor: ((SectionHeaderFooterInformation) -> String?)?
open var createView: ((SectionHeaderFooterInformation) -> Type?)?
}

extension SectionHeaderFooter: SectionHeaderFooterDelegateType {
func configureView(tableView: UITableView, view: UIView, section: Int) {
func configureView(_ tableView: UITableView, view: UIView, section: Int) {
guard let genericView = view as? Type else {
fatalError()
}
configureView?(genericView, (self, tableView, section))
}

func heightFor(tableView: UITableView, section: Int) -> CGFloat? {
func heightFor(_ tableView: UITableView, section: Int) -> CGFloat? {
return heightFor?((self, tableView, section)) ?? height
}

func titleFor(tableView: UITableView, section: Int) -> String? {
func titleFor(_ tableView: UITableView, section: Int) -> String? {
return titleFor?((self, tableView, section)) ?? title
}

func viewFor(tableView: UITableView, section: Int) -> UIView? {
func viewFor(_ tableView: UITableView, section: Int) -> UIView? {
return createView?((self, tableView, section))
}
}
8 changes: 4 additions & 4 deletions Classes/SectionHeaderFooterType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public protocol SectionHeaderFooterType {
}

protocol SectionHeaderFooterDelegateType {
func configureView(tableView: UITableView, view: UIView, section: Int)
func heightFor(tableView: UITableView, section: Int) -> CGFloat?
func titleFor(tableView: UITableView, section: Int) -> String?
func viewFor(tableView: UITableView, section: Int) -> UIView?
func configureView(_ tableView: UITableView, view: UIView, section: Int)
func heightFor(_ tableView: UITableView, section: Int) -> CGFloat?
func titleFor(_ tableView: UITableView, section: Int) -> String?
func viewFor(_ tableView: UITableView, section: Int) -> UIView?
}
8 changes: 4 additions & 4 deletions Classes/SectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public protocol SectionType {
var footer: SectionHeaderFooterType? { get }

var rowCount: Int { get }
func rowFor(row: Int) -> RowType
func rowFor(indexPath: NSIndexPath) -> RowType
func rowFor(_ row: Int) -> RowType
func rowFor(_ indexPath: IndexPath) -> RowType

func removeRow(index: Int) -> RowType
func insertRow(row: RowType, index: Int)
func removeRow(_ index: Int) -> RowType
func insertRow(_ row: RowType, index: Int)
}
Loading

0 comments on commit 1697dbd

Please sign in to comment.