Skip to content

Commit

Permalink
Bump version to include #5
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSoftware committed Jan 31, 2016
1 parent 7014a7a commit 3d49c30
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 2.1.0

* Added support for direct instantiation of arbitrary `UIView` from a nib.
[@jakubvano](https://github.com/jakubvano), [#5](https://github.com/AliSoftware/Reusable/pull/5)

There is now a dedicated `NibLoadable` protocol which can be used on any arbitrary `UIView` (even non-"reusable" views) to load it from a XIB (via the `loadFromNib()` function injected via the protocol extension).

_The `NibReusable` protocol still exists for reusable cells but is now declared just as a combination of both the `Reusable` and `NibLoadable` protocols.

## 2.0.0

* Fixed missing `public` visibility for the protocols and extensions
Expand Down
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

![Reusable](Example/ReusableDemo/Assets.xcassets/AppIcon.appiconset/AppIcon-167.png)

A Swift mixin to use `UITableViewCells` and `UICollectionViewCells` in a **type-safe way**, without the need to manipulate their `String`-typed `reuseIdentifiers`.
A Swift mixin to use `UITableViewCells` and `UICollectionViewCells` in a **type-safe way**, without the need to manipulate their `String`-typed `reuseIdentifiers`. This library also supports arbitrary `UIView` to be loaded via a XIB using a simple call to `loadFromNib()`

[![Platform](http://cocoapod-badges.herokuapp.com/p/Reusable/badge.png)](http://cocoadocs.org/docsets/Reusable)
[![Version](http://cocoapod-badges.herokuapp.com/v/Reusable/badge.png)](http://cocoadocs.org/docsets/Reusable)

*TL;DR:*

* Make your `UITableViewCell` and `UICollectionViewCell` conform to either `Reusable` or `NibReusable`
* Mark your `UITableViewCell` and `UICollectionViewCell` classes to conform to either `Reusable` or `NibReusable` (no additional code to implement!)
* Then simply use `tableView.dequeueReusableCell(indexPath: indexPath) as MyCustomCell` and you'll get a dequeued instance of the expected cell class in return. **No need for you to manipulate `reuseIdentifiers` manually!**

No more force-casting the returned `UITableViewCell` instance down to your `MyCustomCell` class, and no more fear that you'll mismatch the `reuseIdentifier` and the class you down-cast to. Now all you have is **a beautiful code and type-safe cells**!

> For more information on how this works, see [my dedicated blog post about this technique](http://alisoftware.github.io/swift/generics/2016/01/06/generic-tableviewcells/).
Note: the `Reusable` library can also be used to mark any arbitrary `UIView` as `NibLoadable` and then simply create an instance of that XIB-based view using `MyCustomView.loadFromNib()`.

## Declaring your cell subclasses

First, declare your cells to conform to:
Expand Down Expand Up @@ -77,6 +79,16 @@ class NibBasedCollectionViewCell: UICollectionViewCell, NibReusable {
}
```

### Example with a XIB-based arbitrary UIView

`Reusable` can also be used to load an arbitrary `UIView` subclass (even a non-reusable, non-cell view) designed in a XIB by simply marking it as `NibLoadable`:

```swift
class NibBasedRandomView: UIView, NibLoadable {
// The rest of the view code goes here
}
```

## Registering your cells by code

Then to use those cells, you'll register them like this, without the need to manipulate any `reuseIdentifier` anywhere in the code:
Expand Down Expand Up @@ -117,9 +129,20 @@ extension MyViewController: UITableViewDataSource {
}
```

## Instantiating arbitrary views from XIBs

If you mark an arbitrary (non-cell) `UIView` as `NibLoadable` [as demonstrated above](#example-with-a-xib-based-arbitrary-uiview), you can also instantiate such a view using its Nib by calling `loadFromNib()`:

```swift
let instance1 = NibBasedRandomView.loadFromNib()
let instance2 = NibBasedRandomView.loadFromNib()
let instance3 = NibBasedRandomView.loadFromNib()
```

## Customization

`Reusable` and `NibReusable` are what is usually called [Mixins](http://alisoftware.github.io/swift/protocol/2015/11/08/mixins-over-inheritance/), which basically is a Swift protocol with a default implementation provided for all of its methods. The main benefit is that you don't need to add any code, just conform to `Reusable` or `NibReusable` and you're ready to go.
`Reusable`, `NibLoadable` and `NibReusable` are what is usually called [Mixins](http://alisoftware.github.io/swift/protocol/2015/11/08/mixins-over-inheritance/), which basically is a Swift protocol with a default implementation provided for all of its methods. The main benefit is that **you don't need to add any code**: just conform to `Reusable`, `NibLoadable` or `NibReusable` and you're ready to go.

But of course, those provided implementations are just _default implementations_. That means that if you need **you can still provide your own implementations** in case for some reason some of your cells don't follow the classic configuration of using the same name for both the class, the `reuseIdentifier` and the XIB file.

Expand Down
2 changes: 1 addition & 1 deletion Reusable.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Reusable"
s.version = "2.0.0"
s.version = "2.1.0"
s.summary = "A Swift Mixin to deal with reusable UITableView and UICollectionView cells"

s.description = <<-DESC
Expand Down

0 comments on commit 3d49c30

Please sign in to comment.