Giter Site home page Giter Site logo

heyscholar / segueinginfo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adorkable/segueinginfo

0.0 1.0 0.0 153 KB

Simple way to pass data between segueing View Controllers in an iOS Storyboard

License: MIT License

Ruby 20.06% Swift 74.87% Objective-C 2.77% Shell 2.30%

segueinginfo's Introduction

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

segueinginfo's People

Contributors

yoiang avatar waffle-iron avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.