Swiftpack.co - florianbuerger/InterfaceBacked as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by florianbuerger.
florianbuerger/InterfaceBacked 2.4.0
Simplify usage of storyboard & nib files
⭐️ 5
🕓 3 years ago
iOS
.package(url: "https://github.com/florianbuerger/InterfaceBacked.git", from: "2.4.0")

Interface Backed

Carthage compatible

Original idea and implementation by Benjamin Sandofsky's gist

I just simplified the code a bit and put it in a Framework. Added a similar approach for UIView subclasses that rely on a .nib file.

Released under the MIT license

Usage

Your classes must be declared final to adopt the protocol.

UIViewController

final class ViewController: UIViewController, StoryboardBacked {}

let vc = ViewController.newFromStoryboard()

You can use a custom name or a custom bundle. The function defaults to a storyboard named as the view controller and to the bundle the class is in. So this works even when your view controller class in inside a framework and not the main bundle.

Hint: Double check that you made your custom view controller the initial view controller for the storyboard.

UITableViewCell

final class Cell: UITableViewCell, NibBackedCell {}

tableView.registerNib(Cell.cellNib(), forCellReuseIdentifier: Cell.identifier())

Hint: Double check the identifier for the cell in the .nib file. It must reflect the name of the class.

For more information check the included Example target.

GitHub

link
Stars: 5
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics