Skip to content

Commit

Permalink
Correct the interface of bind to conform to grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shunki Tan committed Feb 5, 2017
1 parent 8d00196 commit 0e43147
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Instantiate/Bindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public protocol Bindable {
associatedtype Parameter
/// `bind` call after prepare user intarfaces. e.g.) `UIViewController.viewDidLoad`, `UIView.awakeFromNib`.
/// - parameter parameter: User interface needs to some parameter(s).
func bind(to parameter: Parameter)
func bind(_ parameter: Parameter)
}

public extension Bindable where Parameter == Void {
func bind(to parameter: Parameter) {
func bind(_ parameter: Parameter) {

}
}
2 changes: 1 addition & 1 deletion Instantiate/Nib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension NibInstantiatable where Self: NSObject {
public extension NibInstantiatable where Self: UIView {
public static func instantiate(with parameter: Parameter) -> Self {
let _self = nib.instantiate(withOwner: nil, options: nil)[instantiateIndex] as! Self
_self.bind(to: parameter)
_self.bind(parameter)
return _self
}
}
Expand Down
6 changes: 3 additions & 3 deletions Instantiate/Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension UITableView {

public func dequeReusableCell<C: UITableViewCell>(type: C.Type, for indexPath: IndexPath, with parameter: C.Parameter) -> C where C: Reusable, C: Bindable {
let cell = dequeReusableCell(type: type, for: indexPath)
cell.bind(to: parameter)
cell.bind(parameter)
return cell
}
}
Expand All @@ -49,7 +49,7 @@ public extension UICollectionView {

public func dequeReusableCell<C: UICollectionViewCell>(type: C.Type, for indexPath: IndexPath, with parameter: C.Parameter) -> C where C: Reusable, C: Bindable {
let cell = dequeReusableCell(type: type, for: indexPath)
cell.bind(to: parameter)
cell.bind(parameter)
return cell
}
}
Expand All @@ -69,7 +69,7 @@ public extension UICollectionView {

public func dequeueReusableSupplementaryView<C: UICollectionReusableView>(type: C.Type, of kind: String, for indexPath: IndexPath, with parameter: C.Parameter) -> C where C: Reusable, C: Bindable {
let view = dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: C.reusableIdentifier, for: indexPath) as! C
view.bind(to: parameter)
view.bind(parameter)
return view
}
}
Expand Down
2 changes: 1 addition & 1 deletion Instantiate/Storyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public extension StoryboardInstantiatable where Self: UIViewController {
_self = storyboard.instantiateViewController(withIdentifier: identifier) as! Self
}
_ = _self.view // workaround: load view before bind.
_self.bind(to: parameter)
_self.bind(parameter)
return _self
}
}
16 changes: 8 additions & 8 deletions InstantiateTestsResource/Resources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ final class View: UIView, NibInstantiatable {
typealias Parameter = UIColor
var parameter: Parameter!

func bind(to parameter: UIColor) {
func bind(_ parameter: UIColor) {
self.backgroundColor = parameter
}
}

final class ViewController: UIViewController, StoryboardInstantiatable {
typealias Parameter = String

func bind(to parameter: String) {
func bind(_ parameter: String) {
self.label.text = parameter
}

Expand All @@ -37,7 +37,7 @@ final class ViewController: UIViewController, StoryboardInstantiatable {
typealias Wrapped = View
@IBInspectable var color: UIColor = .white {
didSet {
viewIfLoaded?.bind(to: color)
viewIfLoaded?.bind(color)
}
}

Expand All @@ -64,7 +64,7 @@ final class TableViewCell: UITableViewCell, Reusable, NibType, Bindable {
typealias Parameter = Int
@IBOutlet weak var label: UILabel!

func bind(to parameter: Int) {
func bind(_ parameter: Int) {
label.text = "\(parameter)"
}
}
Expand All @@ -82,7 +82,7 @@ final class ViewController3: UIViewController, StoryboardInstantiatable {
}
}

func bind(to parameter: [Int]) {
func bind(_ parameter: [Int]) {
dataSource = parameter
tableView.reloadData()
}
Expand Down Expand Up @@ -110,7 +110,7 @@ final class CollectionViewCell: UICollectionViewCell, Reusable, NibType, Bindabl
typealias Parameter = String
@IBOutlet weak var label: UILabel!

func bind(to parameter: String) {
func bind(_ parameter: String) {
label.text = parameter
}
}
Expand All @@ -119,7 +119,7 @@ final class CollectionReusableView: UICollectionReusableView, Reusable, NibType,
typealias Parameter = String
@IBOutlet weak var label: UILabel!

func bind(to parameter: String) {
func bind(_ parameter: String) {
label.text = parameter
}
}
Expand All @@ -138,7 +138,7 @@ final class ViewController4: UIViewController, StoryboardInstantiatable {
}
}

func bind(to parameter: Array<(header: String, items: [String])>) {
func bind(_ parameter: Array<(header: String, items: [String])>) {
dataSource = parameter
collectionView.reloadData()
}
Expand Down

0 comments on commit 0e43147

Please sign in to comment.