Latest | 0.2.0 |
---|---|
Homepage | https://github.com/cjndubisi/CJNibSegue |
License | MIT |
Platforms | ios 8.0 |
Authors |
[](https://travis-ci.org/Chijioke Ndubisi/CJNibSegue)
Requirements
- Xcode 8
- Swift 3
Installation
CJNibSegue is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "CJNibSegue"
Usage
Create Identifiers
Create an Enum that conforms to CJNibSegueIdentifiable
– a protocol composed of RawRepresentable
, Hashable
// Step 1
// Making the enum a string makes the it conform to RawRepresentable and Hashable
enum ChatSegueIdentifiers: String, CJNibSegueIdentifiable {
case chat
case call
}
Register Identifers
Register identifiers anywhere anywhere.
Most times you need to initialize a view controller’s constant with a custom init.
registerSegue(withIdentifier:fromSource:toDestination:) captures self so at the time of perfoming the segue all the variables needed to create a valid destination view controller are set.
self.registerSegue(withIdentifier: ChatSegueIdentifiers.chat) { [unowned self] in // capture self
let destination = DestinationViewController(text: self.text)
return destination
}
Conformance
UIViewController by defaut conform to CJNibViewController however, to prepare for the segue your view controller subclass has to conform to CJNibViewControllerDelegate.
// Comform to CJNibViewController
extension SourceViewController: CJNibViewControllerDelegate {
func prepare(for nibSegue: NibSegue, sender: Any?) {
if let segue = nibSegue as? CJNibSegue<SegueIdenifiers, SourceViewController, DestinationViewController>
{
switch segue.nibIdentiifer {
case .chat:
// set up detination
}
}
}
}
Trigger Segue
Call performSegue(withIdentifier: .chat,sender: cell)
Contribution
All are well come via github issues
Author
Chijioke Ndubisi, [email protected]
License
CJNibSegue is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "CJNibSegue", "version": "0.2.0", "summary": "Segue with Nib", "description": "A type safe implementation for segues using Nibs", "homepage": "https://github.com/cjndubisi/CJNibSegue", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Chijioke Ndubisi": "[email protected]" }, "source": { "git": "https://github.com/cjndubisi/CJNibSegue.git", "tag": "0.2.0" }, "platforms": { "ios": "8.0" }, "source_files": "CJNibSegue/Classes/**/*", "pushed_with_swift_version": "3.0" }
Sat, 18 Feb 2017 22:20:03 +0000