Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README for Swift 3 #41

Merged
merged 3 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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

## 4.0.2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have told you: I usually just use ## Master for entries not released yet
(I might not release a new version (4.0.2) just for this, and in case the next PR adds something breaking the next version might not end up being 4.0.2 but maybe 4.1.0 or whatnot 😉 )


* Updated README instructions to Swift 3.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be nitpicking, but could you please add 2 spaces at the end of that line?

That's a trick related to Markdown formatting: adding two spaces at the end of a line allows to go to the next line while staying in the same paragraph/bullet point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha I was wondering how the other entries got a new line! Yeah no worries.

[@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