Description
Releasing this library with documentation available on GitHub, an example project, and high test coverage. It's been tested in production by the iOS team at VTS in multiple iOS applications.
Release blog:
https://buildingvts.com/idiomatic-swift-safer-view-view-controller-instantiation-ab0c7f41245b
ReusableViews alternatives and similar libraries
Based on the "Layout" category.
Alternatively, view ReusableViews alternatives based on common mentions on social networks and blogs.
-
PureLayout
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible. -
PinLayout
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer] -
FlexLayout
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax. -
MisterFusion
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class. -
QuickLayout
Written in pure Swift, QuickLayout offers a simple and easy way to manage Auto Layout in code. -
ManualLayout
✂ Easy to use and flexible library for manually laying out views and layers for iOS and tvOS. Supports AsyncDisplayKit. -
FrameLayoutKit
A super fast and easy-to-use layout library for iOS. FrameLayoutKit supports complex layouts, including chaining and nesting layout with simple and intuitive operand syntax. -
JustUiKit
iOS UI Kit With Android-Style Tools. JustUiKit contains JustLinearLayout, JustFrameLayout and so on. It is designed to make Android developers build iOS UI easily. Also for iOS developers, it provides a new way to build UI. -
CGLayout
Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Not Apple Autolayout wrapper. Provides placeholders. Linux support.
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of ReusableViews or a related project?
README
ReusableViews
Why?
This extension package solves the following problems:
- Forces your team to adhere to standard practices by:
- Making storyboard identifiers the same as their class names
- Making UITableViewCell and UICollectionViewCell reuse identifiers the same as their class name
- Making UICollectionView supplementary views and UITableViewHeaderFooterView reuse identifiers the same as their class name
- Removes the need to force unwrap or force cast cells/headers as you dequeue
- Removes the need to force unwrap or force cast UIViewControllers as you instantiate them from a storyboard
If you're a user of SwiftLint, you'll greatly appreciate the reduced number of warnings and no more need for snippets in the vein of:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "...", for: indexPath) as? MyCustomCellType else {
fatalError("We didn't get the cell")
}
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Convenient Instantiation of a View From a Nib
Requires that your view conforms to NibLoadableView
.
let view = MyNibLoadableView.create()
Instantiation of a UIViewController From a Storyboard
Requires that a class has the same storyboard identifier as its class name.
let myStoryboard: UIStoryboard = ...
let myCustomViewController = myStoryboard.instantiateViewControllerOfType(MyCustomViewController.self) as MyCustomViewController
Dequeueing and Registering a UITableViewCell
Requires that a class has the same reuse identifier as its class name. You must register your cell type first.
// Registration
tableView.register(MyCustomCellType.self)
// Dequeueing
let cell = tableView.dequeueReusableCell(for: indexPath) as MyCustomCellType
Dequeueing and Registering a UICollectionViewCell
Requires that a class has the same reuse identifier as its class name. You must register your cell type first.
// Registration
collectionView.register(MyCustomCellType.self)
// Dequeueing
let cell = collectionView.dequeueReusableCell(for: indexPath) as MyCustomCellType
Dequeueing and Registering a UITableViewHeaderFooterView
Requires that a class has the same reuse identifier as its class name. You must register your cell type first.
// Registration
tableView.register(MyCustomHeaderFooterView.self)
/// Dequeueing
let header = tableView.dequeueReusableHeaderFooterView(inSection: section) as MyCustomHeaderFooterView
Dequeueing and Registering a UICollectionView Supplementary View
Requires that a class has the same reuse identifier as its class name. You must register your view type first.
// Registration
collectionView.register(MyCustomSupplementaryView.self, forSupplementaryViewElementOfKind: .sectionHeader) // or .sectionFooter
// Dequeueing
let view = collectionView.dequeueReusableSupplementaryView(ofKind: .sectionHeader, for: indexPath) as MyCustomSupplementaryView // also takes .sectionFooter
Registering a view backed by a nib
Views backed by nibs must implement the NibLoadableView
protocol. The protocol has a pre-defined extension, such that your view doesn't need to add any methods or properties.
class MyCoolCell: UITableViewCell, NibLoadableView {
...
}
Installation
ReusableViews is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ReusableViews"
Author
Hesham Salman, [email protected]
Twitter: @WhatsASoftware
License
ReusableViews is available under the MIT license. See the LICENSE file for more info.
*Note that all licence references and agreements mentioned in the ReusableViews README section above
are relevant to that project's source code only.