Skip to content

This library allows you to specify a custom UIKit view as reusable, providing simple shorthand and type-safety for common types like UICollectionViewCell, UITableViewCell, and other views which can be loaded from a storyboard or nib.

License

Notifications You must be signed in to change notification settings

ts0l/UIReusableView

Repository files navigation

UIReusableView

This library allows you to specify a custom UIKit view as reusable, providing simple shorthand and type-safety for common types like UICollectionViewCell, UITableViewCell, and other views which can be loaded from a storyboard or nib.

Installation

Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Follow the prompts using the URL for this repository.

Usage

1. Conforming

class CustomTableViewCell: UITableViewCell, UIReusableView { }
class CustomCollectionViewCell: UICollectionViewCell, UIReusableView { }

2. Registering

override func viewDidLoad() {
    super.viewDidLoad()
    CustomTableViewCell.register(in: tableView)
}
override func viewDidLoad() {
    super.viewDidLoad()
    CustomCollectionViewCell.register(in: collectionView)
}

3. Dequeuing

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: CustomTableViewCell = .dequeue(from: tableView, at: indexPath)
    return cell
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell: CustomCollectionViewCell = .dequeue(from: collectionView, at: indexPath)
    return cell
}

About

This library allows you to specify a custom UIKit view as reusable, providing simple shorthand and type-safety for common types like UICollectionViewCell, UITableViewCell, and other views which can be loaded from a storyboard or nib.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages