Skip to content

Instantly share code, notes, and snippets.

@brendanjerwin
Last active February 11, 2016 23:41
Show Gist options
  • Save brendanjerwin/5677203 to your computer and use it in GitHub Desktop.
Save brendanjerwin/5677203 to your computer and use it in GitHub Desktop.
A pattern for increasing the testability of `prepareForSegue:sender:`
-(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 beginLoadEntity:self.selectedEntityList];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment