Slide 1

Slide 1 text

How I Learned to Stop Worrying and Love the Storyboard Josh Johnson · @jnjosh · jnjosh.com

Slide 2

Slide 2 text

I spent a lot of time hating on Storyboards

Slide 3

Slide 3 text

So, on any given NSCoder Night…

Slide 4

Slide 4 text

“Storyboards are awesome!” 1 Abbie

Slide 5

Slide 5 text

“That's crazy, I'll just write the code!" 1 Me

Slide 6

Slide 6 text

“No really, you should look again…” 1 Abbie

Slide 7

Slide 7 text

“Why do people hate writing code?” 1 Me

Slide 8

Slide 8 text

So, then we get a client project that uses Storyboards

Slide 9

Slide 9 text

I cry

Slide 10

Slide 10 text

But we decide to keep the Storyboards

Slide 11

Slide 11 text

I cry, again

Slide 12

Slide 12 text

Spoiler: It hasn't been so bad…

Slide 13

Slide 13 text

A partial list of things we've done to work with Storyboards.

Slide 14

Slide 14 text

Use Multiple Storyboards

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Crossing to another Storyboard UIViewController *mainViewController = [[UIStoryboard storyboardWithName:@"MainWorkflow" bundle:nil] instantiateInitialViewController]; [self presentViewController:mainViewController animated:YES completion:nil];

Slide 17

Slide 17 text

Dynamic Prepare For Seque

Slide 18

Slide 18 text

This can get ugly… - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSString *identifier = segue.identifier; if ([identifier isEqualToString:@"FriendsToFacebookFriends"]) { // … } else if ([identifier isEqualToString:@"FriendsToTwitterFriends"]) { // … } else if ([identifier isEqualToString:@"FriendsToContacts"]) { // … } }

Slide 19

Slide 19 text

Dynamic Method Dispatch! - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [self twt_prepareForSegue:segue sender:sender]; } /// - (void)twt_prepareForFriendsToFacebookFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToTwitterFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;

Slide 20

Slide 20 text

UIViewController+TWTPrepareForSegue.h https://github.com/twotoasters/Toast pod 'TWTToast/UIKit/PrepareForSegue', '~> 0.8'

Slide 21

Slide 21 text

Multiple Segues to a Single View

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Manually Performing the Segue - (void)itemSelected:(TWTItem *)item { if ([self shouldPerformSegueWithIdentifier:item.segueIdentifier sender:self]) { [self performSegueWithIdentifier:item.segueIdentifier sender:self]; } }

Slide 24

Slide 24 text

Remember Dynamic Method Dispatch? - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { [self twt_prepareForSegue:segue sender:sender]; } /// - (void)twt_prepareForFriendsToFacebookFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToTwitterFriendsSegue:(UIStoryboardSegue *)segue sender:(id)sender; - (void)twt_prepareForFriendsToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;

Slide 25

Slide 25 text

Naming Conventions

Slide 26

Slide 26 text

Name your Segue Identifiers consistently static NSString *const kInviteSourceToContactsSegueIdentifier = @"InviteSourceToContacts"; static NSString *const kInviteSourceToFacebookSegueIdentifier = @"InviteSourceToFacebook"; static NSString *const kInviteSourceToTwitterSegueIdentifier = @"InviteSourceToTwitter"; /// - (void)twt_prepareForInviteSourceToContactsSegue:(UIStoryboardSegue *)segue sender:(id)sender;

Slide 27

Slide 27 text

Nib-backed Views

Slide 28

Slide 28 text

@protocol TWTNibBackedView + (UINib *)nib; @end /// In TWTTestCollectionViewCell + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass(self) bundle:nil]; } /// In TWTTestCollectionViewController -viewDidLoad [collectionView registerNib:[TWTTestCollectionViewCell nib] forCellWithReuseIdentifier:kCellIdentifier];

Slide 29

Slide 29 text

So, It hasn't been so bad

Slide 30

Slide 30 text

Keep an open mind

Slide 31

Slide 31 text

Thanks! Questions? Josh Johnson · @jnjosh · jnjosh.com