Latest 0.4.0
Homepage https://github.com/marty-suzuki/ReuseCellConfigure
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

Platform
Language
Version
Carthage compatible
License

You can configure ReusableCell without casting!

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

If you install from pod, you have to write import ReuseCellConfigure.

// LeftIconTableViewCell.swift
class LeftIconTableViewCell: UITableViewCell, ReusableViewProtocol {
    typealias RegisterType = RegisterNib
}

// ViewController.swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: UITableViewCell?
    let alphabet = String(describing: UnicodeScalar("A".unicodeScalars.first!.value + UInt32(indexPath.row))!)
    switch indexPath.row % 2 {
    case 0:
        cell = tableView.dequeue(with: LeftIconTableViewCell.self) { cell in
            cell.alphabetLabel.text = alphabet
            cell.randomBackgoundColor()
        }
    case 1:
        cell = tableView.dequeue(with: RightIconTableViewCell.self) { cell in
            cell.alphabetLabel.text = alphabet
        }
    default:
        cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell")
    }
    return cell!
}
// ReusableHeaderView.swift
class LeftIconTableViewCell: UICollectionReusableView, ReusableViewProtocol {
    typealias RegisterType = RegisterClass
}

// ViewController.swift
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let reusableView: UICollectionReusableView? = nil
    switch UICollectionView.ElementKind(rawValue: kind) {
        case .Some(.Header):
            return collectionView.dequeue(with: ReusableHeaderView.self, of: .Header, for: indexPath) { view in
                view.backgroundColor = .redColor()
            }
        case .Some(.Footer):
            return collectionView.dequeue(with: ReusableHeaderView.self, of: .Footer, for: indexPath) { view in
                view.backgroundColor = .blueColor()
            }
        default:
            return reusableView
    }
}

Requirements

  • Xcode 9.1 or greater
  • iOS 8.0 or greater

Installation

CocoaPods

ReuseCellConfigure is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "ReuseCellConfigure"

Carthage

If you’re using Carthage, simply add
ReuseCellConfigure to your Cartfile:

github "marty-suzuki/ReuseCellConfigure"

Make sure to add ReuseCellConfigure.framework to "Linked Frameworks and Libraries" and "copy-frameworks" Build Phases.

Author

Taiki Suzuki, [email protected]

License

ReuseCellConfigure is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ReuseCellConfigure",
    "version": "0.4.0",
    "summary": "You can configure ReusableCell without casting!",
    "homepage": "https://github.com/marty-suzuki/ReuseCellConfigure",
    "license": "MIT",
    "authors": {
        "Taiki Suzuki": "[email protected]"
    },
    "source": {
        "git": "https://github.com/marty-suzuki/ReuseCellConfigure.git",
        "tag": "0.4.0"
    },
    "social_media_url": "https://twitter.com/marty_suzuki",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "ReuseCellConfigure/*.{swift}",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This