Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How I Learned to Quit Worrying and Love Storyboards

How I Learned to Quit Worrying and Love Storyboards

For a long time, I've been convinced that the only way to build iOS applications. Recently I've made the switch to use Storyboards for a project. At CocoaHeads May in Durham, NC I shared some of the things we've been doing to stay productive while working with something that was new to us.

Ff90de2297b7e3136fa3c4a971b0b1c5?s=128

Josh Johnson

May 22, 2014
Tweet

Transcript

  1. How I Learned to Stop Worrying and Love the Storyboard

    Josh Johnson · @jnjosh · jnjosh.com
  2. I spent a lot of time hating on Storyboards

  3. So, on any given NSCoder Night…

  4. “Storyboards are awesome!” 1 Abbie

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

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

  7. “Why do people hate writing code?” 1 Me

  8. So, then we get a client project that uses Storyboards

  9. I cry

  10. But we decide to keep the Storyboards

  11. I cry, again

  12. Spoiler: It hasn't been so bad…

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

    Storyboards.
  14. Use Multiple Storyboards

  15. None
  16. Crossing to another Storyboard UIViewController *mainViewController = [[UIStoryboard storyboardWithName:@"MainWorkflow" bundle:nil]

    instantiateInitialViewController]; [self presentViewController:mainViewController animated:YES completion:nil];
  17. Dynamic Prepare For Seque

  18. 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"]) { // … } }
  19. 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;
  20. UIViewController+TWTPrepareForSegue.h https://github.com/twotoasters/Toast pod 'TWTToast/UIKit/PrepareForSegue', '~> 0.8'

  21. Multiple Segues to a Single View

  22. None
  23. Manually Performing the Segue - (void)itemSelected:(TWTItem *)item { if ([self

    shouldPerformSegueWithIdentifier:item.segueIdentifier sender:self]) { [self performSegueWithIdentifier:item.segueIdentifier sender:self]; } }
  24. 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;
  25. Naming Conventions

  26. 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;
  27. Nib-backed Views

  28. @protocol TWTNibBackedView <NSObject> + (UINib *)nib; @end /// In TWTTestCollectionViewCell

    + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass(self) bundle:nil]; } /// In TWTTestCollectionViewController -viewDidLoad [collectionView registerNib:[TWTTestCollectionViewCell nib] forCellWithReuseIdentifier:kCellIdentifier];
  29. So, It hasn't been so bad

  30. Keep an open mind

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