Deprecated, please use RxCocoa
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.
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"
or
#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;
destionationController.name = theSegue.identifier;
}];
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"];
or
[self SH_performSegueWithIdentifier:@"push"
andDestionationViewController:^(UIViewController * theDestinationViewController) {
theDestinationViewController.SH_userInfo = myDictionary
}];
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);
else
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.
email: seivan.heidari@icloud.com
twitter: @seivanheidari
SHSegueBlocks is © 2013 Seivan and may be freely
distributed under the MIT license.
See the LICENSE.md
file.