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

RubyMotion for Rails Developers - Misconception...

RubyMotion for Rails Developers - Misconceptions & API Design

MotionInMotion talk at the SydInMotion meetup

Jack Watson-Hamblin

April 15, 2014
Tweet

More Decks by Jack Watson-Hamblin

Other Decks in Programming

Transcript

  1. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  2. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  3. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers RUBYMOTION ISN’T

    A FRAMEWORK • RubyMotion is a toolchain • Cocoa / Cocoa Touch is our framework • It’s lower level but much larger than Rails • This means more reusable objects • We also fight against our framework less • It’s better to treat RubyMotion development like you’re
 creating a “plain” Ruby app
  4. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers IT’S OK,

    WE STILL HAVE TOOLS • ProMotion • motion-prime • RubyMotionQuery • BubbleWrap
 • Formotion • Teacup • motion-layout • Sugarcube
  5. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers IT’S OK,

    WE STILL HAVE TOOLS • ProMotion • motion-prime • RubyMotionQuery • BubbleWrap
 • Formotion • Teacup • motion-layout • Sugarcube UnderOS is also a great tool for making iOS more like the web
  6. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers IT’S OK,

    WE STILL HAVE TOOLS • ProMotion • motion-prime • RubyMotionQuery • BubbleWrap
 • Formotion • Teacup • motion-layout • Sugarcube UnderOS is also a great tool for making iOS more like the web A little bird told me there is some great new tools coming soon
  7. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MY POINT

    “Learn Apple’s frameworks before the tools to make them easier”
  8. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  9. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  10. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers CONTROLLERS •

    They serve the same purpose • View Controllers handle one screen • Rails controllers are “stateless” • RubyMotion controllers handle an entire lifecycle
  11. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers THE MAIN

    DIFFERENCE def index! ! # list them! end! ! def show! ! # display one! end! ! ! class TaskListController! ! # list them! end! ! class TaskController! ! # display one! end
  12. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers THE MAIN

    DIFFERENCE • A stateful object to work with • It has lifecycle methods to hook into • Find comfort and rejoice in lots of classes instead of lots of methods • You can see these differences in most areas, not just controllers
  13. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers LIFECYCLE def

    loadView! ! # set up your view! end! ! def viewDidLoad! ! # extra changes to! ! # your view! end! ! def viewWillAppear(a)! ! # data + view! end! ! def viewDidDisappear(a)! ! # let go of things! end
  14. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers LIFECYCLE def

    loadView! ! self.view = TaskView.new! end! ! def viewDidLoad! ! self.view.delete_button! addTarget(! ! self,! ! action: ‘delete_task:',! ! forControlEvents:! UIControlEventTouchUpInside! )! end! def viewWillAppear(animated)! ! @task = Task.find(self.task_id)! ! self.view.update({! ! ! title: @task.title,! ! ! text: @task.notes! ! })! end! ! def delete_task(sender)! ! @task.destroy! end
  15. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  16. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  17. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers VIEWS •

    Lots of subclassing, take advantage of framework classes • Kept clean and reusable with the Composite pattern • It’s worth learning Auto Layout for easier reuse • Use delegates and data sources for talking to the controller • Controller owns the view, it can talk to the view however
  18. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers SUBCLASSING •

    By subclassing we utilise the framework classes • Views are focused on displaying things • We can implement the design in our subclasses • A simple public API for updating can be all we need
  19. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers COMPOSITE PATTERN

    • A hierarchy like the HTML DOM • The system uses this for an event responder chain • Make each part of your screen’s UI a subview • Keep all styling in each class • We can take advantage of it for trickling down data changes • Focus on reuse
  20. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers class TaskView

    < UIView! ! def initialize! ! ! # add subviews! ! end! ! ! def update(data = {})! ! ! # call on subviews! ! end! end! THE TASK APP’S VIEW
  21. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers class TTLabel

    < UILabel! ! def initialize! ! ! # style the view and set up the layout! ! end! ! ! def update(data = {})! ! ! # find the data it cares about and update display! ! end! end! THE TASK APP’S VIEW
  22. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers MISUNDERSTANDINGS 1.

    RubyMotion isn’t a framework 2. Controllers vs View Controllers 3. Views as objects
  23. MotionInMotion @ SydInMotion - RubyMotion for Rails Developers FURTHER RESOURCES

    1. MotionInMotion Episodes 2 & 3 2. My upcoming book “RubyMotion for Rails Developers” 3. WWDC 2012 for Auto Layout 4. Clay Allsopp’s book “RubyMotion” from PragProg