CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✓ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Dec 2014 |
Maintained by Jorge Maroto.
Are you tired to write an ugly and big -prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender: method like that?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"segue1"]) {
UIViewController *destination = segue.destinationViewController;
destination.view.backgroundColor = [UIColor redColor];
} else if ([segue.identifier isEqualToString:@"segue2"]) {
UIViewController *destination = segue.destinationViewController;
destination.view.backgroundColor = [UIColor blueColor];
} else if ([segue.identifier isEqualToString:@"segue3"]) {
UIViewController *destination = segue.destinationViewController;
destination.view.backgroundColor = [UIColor greenColor];
}
...
}Check JMGBlockSegue and enjoy defining a block which will be executed to prepare segue in the same place which you call to performSegue.
Use JMGBlockSegue it's really easy, you only need to drop JMGBlockSegue folder to your project, or if you are a CocoaPods-lover, you can include this line in your Podfile as usual:
pod 'JMGBlockSegue'
After that, you need to import UIViewController+BlockSegue.h on each view controller where you want to configure segues.
JMGBlockSegue can be used in two ways: inline (when you performSegue programatically) or independently (in other line).
Perform segue and configure the block which is executed in the same sentence.
[self performSegueWithIdentifier:@"segueIdentifier" sender:nil withBlock:^(id sender, id destinationVC) {
NSLog(@"Segue configured inline");
destinationVC.user = tmpUser;
}];Configure segue block independently of his execution, this way could be called on viewDidLoad for example, and it's run with both the call performSegueWithIdentifier:sender: method and storyboard segue perform.
[self configureSegue:@"segueIdentifier" withBlock:^(id sender, id destinationVC) {
NSLog(@"I'm a block fired with the segue!");
}];I added some tests as personal exercise, but if you want run them, exec script (it uses xcpretty by supermarin):
./run_tests.sh
runtime.h, thanks buddy!.JMGBlockSegue is available under the MIT license. See the LICENSE file for more info.