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

NibReusable -> Reusable & NibLoadable #37

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## UNRELEASED

* Removed strict `NibReusable` protocol conforming in `register` functions.
You can now make `Reusable` cell, and `NibLoadable` subclass.
Copy link
Owner

Choose a reason for hiding this comment

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

Please add 2 spaces after your full-stop here (see other entries for inspiration).
Ending a line with two spaces in Markdown allows to go to the next line in the same paragraph (like a <br>) in the rendered document.


The typical formatting I use in the CHANGELOG is this, where represent a space:

* Change description.••
  [@your_github_handle](link_to_your_gh_profile)
  [#PR_Num](link_to_this_pr)

[@nekrich](https://github.com/nekrich)
[#37](https://github.com/AliSoftware/Reusable/pull/37)

## 3.0.0

* Converted library and Demo project to Swift 3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Reusable
* Which in fact is just a convenience protocol that combines
* both `NibLoadable` + `Reusable` protocols.
*/
final class MyXIBIndexSquaceCell: UICollectionViewCell, NibReusable {
final class MyXIBIndexSquaceCell: UICollectionViewCell, Reusable, NibLoadable {
Copy link
Owner

Choose a reason for hiding this comment

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

Now that we've decided to keep NibReusable as a typealias, maybe keep the usage of NibReusable in the example project here, especially since it's already explained in the comment that it's in fact just a convenience name combining both.

btw, you might also want to check the doc-comments throughout the code and sample project where we describe NibReusable as "just a convenience protocol that combines both NibLoadable + Reusable protocols" and change it to say it's a "convenience typealias combining NibLoadable & Reusable" instead.

@IBOutlet private weak var sectionLabel: UILabel!
@IBOutlet private weak var rowLabel: UILabel!

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This concept, called a [Mixin](http://alisoftware.github.io/swift/protocol/2015/
## 1. Declare your cells to conform to `Reusable` or `NibReusable`

* Use the `Reusable` protocol if they don't depend on a NIB (this will use `registerClass(…)` to register the cell)
* Use the `NibReusable` protocol if they use a `XIB` file for their content (this will use `registerNib(…)` to register the cell)
* Use the `NibReusable` protocol (aka combination of `Reusable` & `NibLoadable` protocols) if they use a `XIB` file for their content (this will use `registerNib(…)` to register the cell)
Copy link
Owner

Choose a reason for hiding this comment

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

Use the NibReusable typealias


```swift
final class CustomCell: UITableViewCell, Reusable { /* And that's it! */ }
Expand All @@ -55,6 +55,7 @@ final class CustomCell: UITableViewCell, Reusable { /* And that's it! */ }
>
> * For cells embedded in a Storyboard's tableView, either one of those two protocols will work (as you won't register the cell them manually anyway)
> * If you create a XIB-based cell, don't forget to set its _Reuse Identifier_ field in Interface Builder to the same string as the name of the cell class itself.
> * 💡 `NibReusable` is syntax sugar, so you could still use two protocols conformance `Reusable, NibLoadable` instead of `NibReusable`.


<details>
Expand All @@ -77,6 +78,9 @@ final class CodeBasedCustomCell: UITableViewCell, Reusable {

```swift
final class NibBasedCustomCell: UITableViewCell, NibReusable {
// or
// final class NibBasedCustomCell: UITableViewCell, Reusable, NibLoadable {

// Here we provide a nib for this cell class (which, if we don't override the protocol's
// default implementation of `nib`, will use a XIB of the same name as the class)

Expand Down Expand Up @@ -106,7 +110,11 @@ final class CodeBasedCollectionViewCell: UICollectionViewCell, Reusable {
// A UICollectionViewCell using a XIB to define it's UI
// And that will need to register using that XIB
final class NibBasedCollectionViewCell: UICollectionViewCell, NibReusable {
// or
// final class NibBasedCollectionViewCell: UICollectionViewCell, Reusable, NibLoadable {

// The rest of the cell code goes here

}
```
</details>
Expand Down
2 changes: 1 addition & 1 deletion Sources/View/Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public protocol Reusable: class {
/// Make your `UITableViewCell` and `UICollectionViewCell` subclasses
/// conform to this protocol when they *are* NIB-based
/// to be able to dequeue them in a type-safe manner
public protocol NibReusable: Reusable, NibLoadable {}
public typealias NibReusable = Reusable & NibLoadable

// MARK: - Default implementation

Expand Down
12 changes: 6 additions & 6 deletions Sources/View/UICollectionView+Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import UIKit

public extension UICollectionView {
/**
Register a NIB-Based `UICollectionViewCell` subclass (conforming to `NibReusable`)
Register a NIB-Based `UICollectionViewCell` subclass (conforming to `Reusable` & `NibLoadable`)

- parameter cellType: the `UICollectionViewCell` (`NibReusable`-conforming) subclass to register
- parameter cellType: the `UICollectionViewCell` (`Reusable` & `NibLoadable`-conforming) subclass to register

- seealso: `register(_:,forCellWithReuseIdentifier:)`
*/
final func register<T: UICollectionViewCell>(cellType: T.Type) where T: NibReusable {
final func register<T: UICollectionViewCell>(cellType: T.Type) where T: Reusable & NibLoadable {
self.register(cellType.nib, forCellWithReuseIdentifier: cellType.reuseIdentifier)
}

Expand Down Expand Up @@ -57,14 +57,14 @@ public extension UICollectionView {
}

/**
Register a NIB-Based `UICollectionReusableView` subclass (conforming to `NibReusable`) as a Supplementary View
Register a NIB-Based `UICollectionReusableView` subclass (conforming to `Reusable` & `NibLoadable`) as a Supplementary View

- parameter supplementaryViewType: the `UIView` (`NibReusable`-conforming) subclass to register as Supplementary View
- parameter supplementaryViewType: the `UIView` (`Reusable` & `NibLoadable`-conforming) subclass to register as Supplementary View
- parameter elementKind: The kind of supplementary view to create.

- seealso: `register(_:,forSupplementaryViewOfKind:,withReuseIdentifier:)`
*/
final func register<T: UICollectionReusableView>(supplementaryViewType: T.Type, ofKind elementKind: String) where T: NibReusable {
final func register<T: UICollectionReusableView>(supplementaryViewType: T.Type, ofKind elementKind: String) where T: Reusable & NibLoadable {
self.register(supplementaryViewType.nib, forSupplementaryViewOfKind: elementKind, withReuseIdentifier: supplementaryViewType.reuseIdentifier)
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/View/UITableView+Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import UIKit

public extension UITableView {
/**
Register a NIB-Based `UITableViewCell` subclass (conforming to `NibReusable`)
Register a NIB-Based `UITableViewCell` subclass (conforming to `Reusable` & `NibLoadable`)

- parameter cellType: the `UITableViewCell` (`NibReusable`-conforming) subclass to register
- parameter cellType: the `UITableViewCell` (`Reusable` & `NibLoadable`-conforming) subclass to register

- seealso: `register(_:,forCellReuseIdentifier:)`
*/
final func register<T: UITableViewCell>(cellType: T.Type) where T: NibReusable {
final func register<T: UITableViewCell>(cellType: T.Type) where T: Reusable & NibLoadable {
self.register(cellType.nib, forCellReuseIdentifier: cellType.reuseIdentifier)
}

Expand Down Expand Up @@ -57,13 +57,13 @@ public extension UITableView {
}

/**
Register a NIB-Based `UITableViewHeaderFooterView` subclass (conforming to `NibReusable`)
Register a NIB-Based `UITableViewHeaderFooterView` subclass (conforming to `Reusable` & `NibLoadable`)

- parameter headerFooterViewType: the `UITableViewHeaderFooterView` (`NibReusable`-conforming) subclass to register
- parameter headerFooterViewType: the `UITableViewHeaderFooterView` (`Reusable` & `NibLoadable`-conforming) subclass to register

- seealso: `register(_:,forHeaderFooterViewReuseIdentifier:)`
*/
final func register<T: UITableViewHeaderFooterView>(headerFooterViewType: T.Type) where T: NibReusable {
final func register<T: UITableViewHeaderFooterView>(headerFooterViewType: T.Type) where T: Reusable & NibLoadable {
self.register(headerFooterViewType.nib, forHeaderFooterViewReuseIdentifier: headerFooterViewType.reuseIdentifier)
}

Expand Down