Skip to content
Segue Blocks and userInfo without swizzling.
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Deprecated, please use RxCocoa


CI Status Version Platform License

This pod is used by SHUIKitBlocks as part of many components covering to plug the holes missing from Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application's architecture.


SHSegueBlocks is a category on top of UIViewController to allow block based segueus without the bullshit of swizzling and other disgusting hacks - also adds the ability to set userInfo on top of a viewController. It's built on top of NSMapTable that works with weakToWeak references between a controller and its blocks and userInfo.

Swizzle & Junk free

No developer psyches were harmed or killed for this. I've noticed other similar libraries all swizzle like there is no tomorrow. If the API can remains the same without Swizzle, then don't fucking Swizzle.

All in all; 100 loc for both userInfo as well as block based segueus. The blocks are gone as soon the segue has finished and userInfo content are gone as soon as the controllers are gone or you set it to nil.


pod 'SHSegueBlocks'


Put this either in specific controllers or your project prefix file

#import "UIViewController+SHSegueBlocks.h"


#import "SHSegueBlocks.h"


With SHSegueBlocks you do it all in one place, like so:

  [self SH_performSegueWithIdentifier:@"push" 
        andDestionationViewController:^(UIViewController * theDestinationViewController) {

    theDestinationViewController.whateverPropety = anotherLocalVariable


or if you want access to the full segue object

  [self SH_performSegueWithIdentifier:@"push" 
              andPrepareForSegueBlock:^(UIStoryboardSegue *theSegue) {

    id<SHExampleProtocol> destionationController =   theSegue.destinationViewController; = theSegue.identifier;


Bonus - SH_userInfo from SHObjectUserInfo

You can directly set a userInfo (mutable) dictionary directly on the segueu selector for the destination controller

  #import "SHObjectUserInfo.h"
[self SH_performSegueWithIdentifier:@"unwinder" withUserInfo:@{@"date" : [NSDate date]}];

In the destinationViewController

self.myDate = self.SH_userInfo[@"date"];


  [self SH_performSegueWithIdentifier:@"push" 
        andDestionationViewController:^(UIViewController * theDestinationViewController) {

    theDestinationViewController.SH_userInfo = myDictionary


Existing Codebase

If you already have

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;

implemented and used within your code base you can use the block handler

-(BOOL)SH_handlesBlockForSegue:(UIStoryboardSegue *)theSegue;

Like this

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; {
  UIViewController * destionationVc = segue.destinationViewController;
  destionationVc.SH_userInfo = nil;
  if([self SH_handlesBlockForSegue:segue])
    NSLog(@"Performed segueue programatically user info: %@", destionationVc.SH_userInfo);
    NSLog(@"Performed unwind segueue via IB");

That will check if there is block and if there is - execute it.


[self performSegueWithIdentifier:@"theIdentifier" sender:@"lolz"];

and then implementing the callback

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; {
  UIViewController * destinationViewController = segue.destinationViewController;
  destionationViewController.whateverPropety = sender;


If you end up using SHSegueBlocks in a project, I'd love to hear about it.

twitter: @seivanheidari


SHSegueBlocks is © 2013 Seivan and may be freely distributed under the MIT license. See the file.

You can’t perform that action at this time.