from ruby on rails to rubymotion - writing your first ios app with rubymotion
DESCRIPTION
This talk is targeted to developers who have experience with Ruby on Rails, but with little to no iOS development experience. We look at a series of gems that can help you get started with RubyMotion, including ProMotion Formotion MotionModel BubbleWrap Teacup Sugarcube MotionAwesomeTRANSCRIPT
![Page 1: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/1.jpg)
RoR to RubyMotionWriting Your First iOS App
With RubyMotion
Michael DenomyBostonMotion User GroupJune 25, 2013
![Page 2: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/2.jpg)
About Me
• Tech Lead at Cyrus Innovation- Agile web consultancy with offices in New
York and Boston
- http://www.cyrusinnovation.com
• Agile and XP practitioner since 2004- Passionate about TDD and pairing
• mdenomy on twitter and github
• Blog at www.mdenomy.wordpress.com
![Page 3: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/3.jpg)
Goals• Capture my experiences getting started
with RubyMotion- Help someone else along
- Get ideas for where to go next
• Target Audience- Developers familiar with Ruby on Rails
- Little to no previous experience with iOS
- Desire to learn
• Some talk, some code
![Page 4: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/4.jpg)
The VisionMVC
Ruby
![Page 5: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/5.jpg)
The Reality initWithNibName?
UIControlEventTouchUpInside?What’s a Nib?
![Page 6: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/6.jpg)
More Cold Hard Facts• RubyMotion is not free- $199.99
- No trial, but 30 day money back
- There is a student discount program
• iOS Developer Program is not free- $99 / year
- Required to deploy to devices and distribute via AppStore
• You will need to understand iOS SDK- iOS documentation is difficult to navigate
![Page 7: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/7.jpg)
It Gets Better
![Page 8: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/8.jpg)
It Gets Better
![Page 9: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/9.jpg)
Good Stuff• Growing community with lots of online
resources
• More and more gems appearing that provide a Rails-like experience
• Free to use the tools you like- Sublime plug in for RubyMotion has code
completion and rake shortcuts
https://github.com/haraken3/SublimeRubyMotionBuilder
![Page 10: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/10.jpg)
MVC in iOS• MVC is MVC right?
• No “convention over configuration”- Have to wire things up manually
• Slightly different terminology that Rails
![Page 11: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/11.jpg)
UIViewControllers• Controller receives actions from the
framework (e.g. view loaded) and the user (e.g. button pressed)- Interacts with Models and View
• UIViewControllers you need to know- UINavigationController
- UITabBarController
- UIViewController
- UITableViewController
![Page 12: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/12.jpg)
Models• Models are PORO’s in RubyMotion
• Support built-in for - attr_accessor
- attr_reader
- attr_writer
• Possible to serialize/deserialize data using NSCoder and NSKeyedArchiver- Looked for other options to support storage
and relationships
![Page 13: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/13.jpg)
Views• UIView is a base class
• Buttons, labels, date pickers, etc., all inherit from UIView
• Views can have subviews- Simplifies screen layout and allows re-use
![Page 14: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/14.jpg)
Let’s Look at Some Code• Basic Navigation- Application Delegate
- Root View Controller
- UITabBarController
- UIViewControllers
![Page 15: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/15.jpg)
MyWines App• I enjoy the occasional glass of wine.
• I would like to have a way to track the wines I like and prices I've paid for them- Record tasting notes
- Record purchases and price info
- Search for wine by name/producer
- Save to Favorites
- Save label picture
• Spoiler alert- I have done next to nothing to style the app
![Page 16: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/16.jpg)
Sketch It Out
It’s a lot cheaper and faster to iterate at this level than in code
![Page 17: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/17.jpg)
What Tools Did I Choose• Bundler - Simplify dependencies
• ProMotion - Screen development and workflow
• Formotion - Entry/edit forms
• MotionModel - Models and relations
• Teacup - Styling DSL
• Sugarcube - UI extensions
• BubbleWrap - I used it for camera, but lots more (JSON, HTTP, RSS, Location, Audio, Video)
• MotionAwesome - Buttons and icons
More at http://rubymotion-wrappers.com/
![Page 18: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/18.jpg)
ProMotion• Simplifies screen development
• Support for table screens- Easily search for table entries
• Helpers for tab and navbar controllers
![Page 19: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/19.jpg)
Formotion• Easily create forms
for entry/edit
• Integrates with ProMotion
• Support For- text
- dates
- sliders
- check boxes
- and many more
![Page 20: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/20.jpg)
MotionModel•Wanted something like ActiveRecord
• Chose MotionModel gem- Lightweight
- Feels Railsy‣ Validations
‣ ActiveRecord-like syntax
‣ Relations
- Serialization / deserialization support
- Actively maintained
- Formotion support(turned out not to matter)
![Page 21: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/21.jpg)
Teacup• Layout and style
your app in a DSL
• Frees you up from layout of screens in XCode
• Allows you to keep your views a lot cleaner
• Hierarchical and supports variables
![Page 22: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/22.jpg)
Sugarcube• Tons of helpful ‘syntactic sugar’ extensions
to make your development easier- conversion of hex color codes to UIColor
- alert and action dialogs
- symbol to iOS, e.g.,‣ :touch.uicontrolevent becomes UIControlEventTouchUpInside
- array helpers
- hash to object conversions
![Page 23: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/23.jpg)
BubbleWrap • Amazing set of tools for- HTTP
- JSON
- RSS
- Camera
- Location
- Alert boxes
- REPL support
• Just using it for the camera in my app
![Page 24: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/24.jpg)
MotionAwesome• Great set of icons and buttons
• Based on FontAwesome
• So far only used it to create a camera button using a camera icon
![Page 25: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/25.jpg)
Deploying to Device• Must be in Apple Developer Program- $99/year
• Get provisioning and developer certificates
• Deploy using rake- rake device
- Make sure to quit iTunes and Image Capture
• Can’t do some things with simulator- e.g. Camera
![Page 26: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/26.jpg)
Where Do I Go Next• Better use of views and subviews- As app evolves will have more common
controls/groups -> re-use
- Easier to lay out due to relative positioning used in subviews
• Better/more styling- Will require more understanding of iOS
• Persist images to file system
• Do more with models- Averages, filtering, etc
![Page 27: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/27.jpg)
Where Do I Go Next• Testing- This was very much a spike, but as the app
evolves want to incorporate more automated testing
- Tested the models, especially persistence and validation since these were areas of risk
- Want to look at more integration testing‣ motion-frank (maintained by Cyrus Innovation)
‣ motion-calabash
![Page 28: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/28.jpg)
Questions I Still Have• ProMotion is awesome, but I wonder if
down the road this paints me into a corner
•Wild West of gems- Will be interesting to see what ideas and
tools rise to the top
• How much iOS should I learn- Interface Builder
- CoreData
![Page 29: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/29.jpg)
Resources• RubyMotion Developer Center- http://www.rubymotion.com/developer-center/
• RubyMotion by Clay Allsop- http://pragprog.com/book/carubym/rubymotion
• iOS Dev Center- Tons of useful info, navigation is horrible- https://developer.apple.com/devcenter/ios/index.action
- https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS
• RubyMotion Wrappers and Libraries- http://rubymotion-wrappers.com/
![Page 30: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/30.jpg)
Questions • Q&A
![Page 31: From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion](https://reader033.vdocuments.site/reader033/viewer/2022052619/5555a948d8b42afe5d8b469c/html5/thumbnails/31.jpg)
RoR to RubyMotionWriting Your First iOS App
Michael DenomyBostonMotion User GroupJune 25, 2013