Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Master

* Updated README instructions to Swift 3.
[@neilkimmett](https://github.com/neilkimmett)
[#41](https://github.com/AliSoftware/Reusable/pull/41)

## 4.0.1

* Added a tvOS target in the Example project.
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ All of that simply by **marking your classes as conforming to a protocol, withou
```swift
// Example of what Reusable allows you to do
final class MyCustomCell: UITableViewCell, Reusable { /* And that's it! */ }
tableView.register(MyCustomCell)
let cell: MyCustomCell = tableView.dequeueReusableCell(indexPath: indexPath)
tableView.register(cellType: MyCustomCell.self)
let cell: MyCustomCell = tableView.dequeueReusableCell(for: indexPath)
```

This concept, called a [Mixin](http://alisoftware.github.io/swift/protocol/2015/11/08/mixins-over-inheritance/) (a protocol with default implementation for all its methods), is explained [here in my blog post](http://alisoftware.github.io/swift/generics/2016/01/06/generic-tableviewcells/) in details.
Expand Down Expand Up @@ -133,7 +133,7 @@ Unless you've prototyped your cell in a Storyboard, you'll have to register the
To do this, instead of calling `registerClass(…)` or `registerNib(…)` using a String-based `reuseIdentifier`, just call:

```swift
tableView.register(theCellClass)
tableView.register(cellType: theCellClass.self)
```

<details>
Expand All @@ -145,8 +145,8 @@ class MyViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
tableView.register(CodeBasedCustomCell) // This will register using the class without using a UINib
tableView.register(NibBasedCustomCell) // This will register using NibBasedCustomCell.xib
tableView.register(cellType: CodeBasedCustomCell.self) // This will register using the class without using a UINib
tableView.register(cellType: NibBasedCustomCell.self) // This will register using NibBasedCustomCell.xib
}
}
```
Expand All @@ -158,9 +158,9 @@ To dequeue a cell (typically in your `cellForRowAtIndexPath` implementation), si

```swift
// Either
let cell = tableView.dequeueReusableCell(indexPath: indexPath) as MyCustomCell
let cell = tableView.dequeueReusableCell(for: indexPath) as MyCustomCell
// Or
let cell: MyCustomCell = tableView.dequeueReusableCell(indexPath: indexPath)
let cell: MyCustomCell = tableView.dequeueReusableCell(for: indexPath)
```

As long as **Swift can use type-inference to understand that you'll want a cell of type `MyCustomCell`** (either using `as MyCystomCell` or explicitly typing the receiving variable `cell: MyCustomCell`), it will magically infer both the cell class to use and thus its `reuseIdentifier` needed to dequeue the cell, and which exact type to return to save you a type-cast.
Expand Down Expand Up @@ -211,7 +211,7 @@ Now all you have is **a beautiful code and type-safe cells**, with compile-type
> // As `self.cellType(for:)` always returns a `ParentCell` (sub-)class, the type
> // of the variable `cell` below is infered to be `ParentCell` too. So only methods
> // declared in the parent `ParentCell` class will be accessible on the `cell` variable.
> let cell = tableView.dequeueReusableCell(indexPath: indexPath, cellType: cellClass)
> let cell = tableView.dequeueReusableCell(for: indexPath, cellType: cellClass)
> return cell
> }
> ```
Expand Down Expand Up @@ -369,7 +369,7 @@ Simply call `instantiate()` on your custom class. This will automatically know w
```swift
func presentSecondary() {
let vc = SecondaryVC.instantitate() // Init from the "SecondaryVC" scene of CustomVC.storyboard
self.presentViewController(vc, animated: true) {}
self.present(vc, animated: true) {}
}
```

Expand Down