Created
May 24, 2013 17:45
-
-
Save brendanjerwin/5645222 to your computer and use it in GitHub Desktop.
Sexy way to manage prepareForSegue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - segues | |
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
DDLogVerbose(@"prepareForSegue: %@", segue.identifier); | |
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"%@ToController:WithSegue:", segue.identifier]); | |
if ([self respondsToSelector:selector]) { | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
[self performSelector:selector withObject:segue.destinationViewController withObject:segue]; | |
#pragma clang diagnostic pop | |
} else { | |
NSException *ex = [NSException exceptionWithName:@"Segue Handler Selector Not Found" reason:[NSString stringWithFormat:@"There is no \"ToController\" selector to handle the segue: %@", segue.identifier] userInfo:@{ @"segue" : segue}]; | |
DDLogError(@"%@", ex); | |
[ex raise]; | |
} | |
} | |
-(void)entityListSegueToController:(TNWEntityTableViewController *)controller WithSegue:(UIStoryboardSegue *)segue { | |
DDLogVerbose(@"Segue to Entity List with Controller: %@ and segue: %@", controller, segue); | |
controller.entity = @"Foobar"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice and testable. I can just test the
__SegueToController:WithSegue:
methods in my unit tests.