Skip to content
Simple way to pass data between segueing View Controllers in an iOS Storyboard
Swift Ruby Objective-C Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Carthage updated to Swift 3 Jun 6, 2017
Cocoapods Updated Cocoapods and Carthage projects for rearranged files Dec 31, 2015
Examples bump to version 4.1.0 Jun 20, 2018
SegueingInfo.xcodeproj Updated for Swift 4.1 Jun 20, 2018
Sources bump to version 4.1.0 Jun 20, 2018
Tests bump to version 4.1.0 Jun 20, 2018
Tools updated generateChangelog to fit with Shellcheck Dec 7, 2015
.gitignore Swift Package Manager support Dec 31, 2015
.overcommit.yml disable overcommit git guilt, never used Dec 31, 2015
.travis.yml
CHANGELOG.md CHANGELOG update Jan 13, 2016
Gemfile touch to cause build Jan 12, 2016
Gemfile.lock Gemfile.lock Jul 10, 2015
LICENSE.md Version 2.0.0! Dec 3, 2015
Package.swift Swift Package Manager support Dec 31, 2015
README.md move waffle.io badge to Contributing section Jan 10, 2016
SegueingInfo.podspec use latest Cocoapods Swift version specification Jun 20, 2018

README.md

SegueingInfo

Build Status Pod Platform Pod License Carthage compatible Pod Version

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!

waffle.io

You can’t perform that action at this time.