CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

CJNibSegue 0.2.0

CJNibSegue 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Chijioke Ndubisi.



  • By
  • 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
}

Conformance

A source view controller must

  • Conform to CJNibViewController and implement
  • The computed property nibSegue: [NibSegue]? to return all possible segues from this source view controller
// Comform to CJNibViewController
extension SourceViewController: CJNibViewController {
    var nibSegue: [NibSegue]? {
        return [
                {
                    let destination = ChatViewController()
                    return CJNibSegue(identifier: ChatSegueIdentifiers.chat,
                         source: self,
                         destination: destination)
                  }()// call function immediately to return a NibSegue
               ]
    }

    (Optional)
    func prepare(for nibSegue: NibSegue, sender: Any?) {
        if let segue = nibSegue as? CJNibSegue<SegueIdenifiers, FirstViewController, SecondViewController> 
        { 
            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.