ChrisBuchholz / Identifiable

Swift library for getting rid of string-based API and instead being type-safe when identifying Storyboards, Nibs, UIViewControllers, UITableViewCells, and UICollectionViewCells

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identifiable

Build Status platforms Swift Package Manager compatible Carthage compatible

⚠️ Identifiable is new-as-can-be and lots of stuff is missing. Feel free to contribute.

Identifiable is a library that lets you get rid of the string-based identifying when instantiating UIViewControllers from storyboards, or when loading a UIStoryboard from a file, and instead deal with them in a type-safe way. Support for reuseIdentifiers for UITableViewCells and UICollectionViewCell is coming.

Usage tl;dr:

Say you have a storyboard called MainStoryboard.storyboard, and inside that, you have an initial view controller of type MyInitialViewController and storyboard ID MyInitialViewController. Inside the storyboard, there is also another view controller of type MySecondViewController with ID MySecondViewController, you can now present the second view controller like this:

import UIKit
import Identifiable

final class MainStoryboard: UIStoryboard, Identifiable {}
final class MyInitialViewController: UIViewController, Identifiable {}
final class MySecondViewController: UIViewController, Identifiable {}

let firstViewController = MainStoryboard.instantiateInitialViewController(MyInitialViewController.self) 
let secondViewController = MainStoryboard.instantiateViewController(MySecondViewController.self)
firstViewController.present(secondViewController, animated: true)

The key here is in the declaration of the classes MainStoryboard, MyInitialViewController, and MySecondViewController. By declaring them with the mixin Identifiable, it becomes possible for them to talk with, and use each other, in an agreed upon language. The only important details to remember is that any UIViewControllers storyboard ID should be the same as it's class name, meaning that the view controller of type MySecondViewController must have the storyboard ID MySecondViewController. Likewise, MainStoryboard will only be identifiable if a storyboard with the file name MainStoryboard.storyboard exists.

For more information, see the Documentation.

Version Compatibility

Note that we're aggressive about pushing master forward along with new versions of Swift. Therefore, we highly recommend against pointing at master, and instead using one of the releases we've provided.

Here is the current Swift compatibility breakdown:

Swift Version Identifiable Version
3.X 0.1.X

Installation

Swift Package Manager

Add the following line to your dependencies list in your Package.swift:

.Package(url: "https://github.com/ChrisBuchholz/Identifiable.git",
majorVersion: 0, minor: 1),

Carthage

Add the following to your Cartfile:

github "ChrisBuchholz/Identifiable"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

Identifiable is Copyright (c) 2016 Christoffer Buchholz. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Swift library for getting rid of string-based API and instead being type-safe when identifying Storyboards, Nibs, UIViewControllers, UITableViewCells, and UICollectionViewCells

License:MIT License


Languages

Language:Swift 100.0%