SegueingInfo 2.1.1

SegueingInfo 2.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Ian Grossberg.



  • By
  • Ian G

SegueingInfo

SegueingInfo provides a few simple ways to passs data between segueing View Controller’s in both iOS and OSX UIStoryboards in a formal, declarative interface which enforcing modularity and weak dependancy between your View Controller implementations.

SegueingInfo requires minimal code to get up and running and using the sender parameter of your performSegueWithIdentifier(identifier:, sender:) function call (performSegueWithIdentifier:sender: selector in ObjC).

Installation

SegueingInfo is available through Carthage, to install simply add the following to your Cartfile:

github "Adorkable/SegueingInfo"

SegueingInfo is also available through Cocoapods, to install simply add the following line to your PodFile:

  pod "SegueingInfo"

Alternatively you can clone the github repo.

Setup

Once installed you’ll first want to import library:

Swift

import SegueingInfo

ObjC

#import <SegueingInfo/SeguingInfo.h>

Once set up, to pass information simply call the appropriate performSegueWithIdentifier, popViewController, etc. call and pass your information into the sender parameter:

Swift

...
self.performSegueWithIdentifier("Next", sender: someObjectWithInfo)
...

ObjC

...
[self performSegueWithIdentifier:"Next" sender:someObjectWithInfo];
...

Next your destination UIViewController subclass must conform to the protocol SegueingInfoDestination, it will receive the information you pass, through the selector

Swift

func destinationPrepareForSegue(segue : UIStoryboardSegue?, info: AnyObject) {
    ...
}

ObjC

- (void)destinationPrepareForSegue:(UIStoryboardSegue *)segue info:(id)info
{
    ...
}

Please note: there is no guarantee as to when your destination View Controller will receive the information relative to viewDidLoad. If you plan on using the passed information to populate your interface make sure you use it when viewDidLoad has been called and store it off when it hasn’t yet.

Note: there are plans to provide a more guaranteed handling of this.

Finally you have two options:

  1. You can change your source UIViewController’s parent class to SegueingInfoViewController to have it automatically forward your information on segue.

  2. The UIViewController (SegueingInfo) category provides the class selector prepareDestinationViewControllerForSegue for forwarding your info on to the destination UIViewController manually. Typically you’ll be calling this from your UIViewController’s prepareForSegue:

    Swift

    override func prepareForSegue(segue : UIStoryboardSegue, sender : AnyObject?) {
        super.prepareForSegue(segue, sender: sender)
    
        self.prepareDestinationViewControlleForSegue(segue, sender: sender)
    }

    ObjC

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    {
        [super prepareForSegue:segue sender:sender];
    
        [self prepareDestinationViewControllerForSegue:segue withInfo:sender];
    }

Contributing

If you have any ideas, suggestions or bugs to report please create an issue labeled feature or bug (check to see if the issue exists first please!). Or suggest a pull request!