Ruby’izing iOS
   Development


Amit Kumar
About me




• Ruby’ist
• Consultant: Tata Consultancy Services Ltd
• Github: toamitkumar
• Twitter: toamit
• toamitkumar.github.com
Released in May, 2012
Released in May, 2012
RubyMotion
RubyMotion

revolutionary toolchain for native iOS application development using Ruby language
RubyMotion

revolutionary toolchain for native iOS application development using Ruby language




                                                neighbor's envy coder’s delight; happiness;
A What ??
A What ??
A What ??

Fork of MacRuby
A What ??

Fork of MacRuby          Compiles into optimized machine code
A What ??

Fork of MacRuby                                  Compiles into optimized machine code




Automatic object memory allocation and reclaim
A What ??

Fork of MacRuby                                  Compiles into optimized machine code




Automatic object memory allocation and reclaim
A What ??

Fork of MacRuby                                  Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode
A What ??

Fork of MacRuby                                  Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode
A What ??

Fork of MacRuby                                      Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode



Ruby-runtime tightly integrated with Obj-C runtime
A What ??

Fork of MacRuby                                      Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode



Ruby-runtime tightly integrated with Obj-C runtime



 Same ancestor as Obj-C
A What ??
A What ??

Fork of MacRuby                                      Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode



Ruby-runtime tightly integrated with Obj-C runtime



 Same ancestor as Obj-C
A What ??

Fork of MacRuby                                      Compiles into optimized machine code




Automatic object memory allocation and reclaim



Compiles the interfaces built in IB of XCode



Ruby-runtime tightly integrated with Obj-C runtime



 Same ancestor as Obj-C                          Object can be shared with no performance cost
Motion Runtime
Motion Runtime
Motion Runtime
Motion Runtime




  Shared Runtime
Motion Runtime




  Shared Runtime
Motion Runtime




  Shared Runtime
Motion Runtime




Foundation Framework
  (NSObject - Kernel)



      Shared Runtime
Motion Runtime




Foundation Framework
  (NSObject - Kernel)



      Shared Runtime
Motion Runtime




Foundation Framework
  (NSObject - Kernel)



      Shared Runtime
Myths
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS

   Cons:
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS

   Cons:
    - Its a bridge that makes native api calls
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS

   Cons:
    - Its a bridge that makes native api calls
    - Runs in single thread of UIWebView which is painfully slow
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS

   Cons:
    - Its a bridge that makes native api calls
    - Runs in single thread of UIWebView which is painfully slow
    - Limited support of direct access to native APIs
Myths


Can I code using RubyMotion without the pain to learn Cocoa Framework ?




PhoneGap like tools are much easier to learn what advantage do I get with RubyMotion ?


   Pros:
    - Very easy to get started; as we all know HTML/JS/CSS

   Cons:
    - Its a bridge that makes native api calls
    - Runs in single thread of UIWebView which is painfully slow
    - Limited support of direct access to native APIs
    - Debugging becomes extremely difficult when you make native api calls
Download & Install




http://sites.fastspring.com/hipbyte/product/rubymotion
The ‘motion’ command
The ‘motion’ command
The ‘motion’ command
The ‘motion’ command
The ‘motion’ command
The ‘motion’ command




Protip: Forcing update to a particular version:
The ‘motion’ command




Protip: Forcing update to a particular version:
The ‘motion’ command




Protip: Forcing update to a particular version:

sudo motion update --force-version=1.2
The ‘motion’ command
The famous ‘Rake’
The famous ‘Rake’
The famous ‘Rake’
The famous ‘Rake’
The famous ‘Rake’
The famous ‘Rake’
Configuration ‘options’
Configuration ‘options’
Configuration ‘options’
Configuration ‘options’
Configuration ‘options’
Configuration ‘options’
Configuration ‘options’
Pro-tip: Other configuration options
Configuration ‘options’
Pro-tip: Other configuration options




app.file_dependencies ‘app/controllers/curves_controller.rb’ => ‘app/controllers/main_controller.rb’
Configuration ‘options’
Pro-tip: Other configuration options




app.file_dependencies ‘app/controllers/curves_controller.rb’ => ‘app/controllers/main_controller.rb’




app.vendor_project
The Soul


Console REPL - Read Evaluate Print Loop
The Soul


Console REPL - Read Evaluate Print Loop




     You feel in-control
The Soul


Console REPL - Read Evaluate Print Loop




     You feel in-control
The Soul


                     Console REPL - Read Evaluate Print Loop




                           You feel in-control



An excellent in-browser demo of REPL:  https://www.pieceable.com/rubymotion-console
Build Process
Build Process




COMPILING
Build Process




COMPILING               LINKING
Build Process




COMPILING               LINKING




PACKAGING
Build Process




COMPILING               LINKING




PACKAGING          CODE SIGN
Testing your code
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
 - Assertions
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
 - Assertions
 - Matchers
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
 - Assertions
 - Matchers
 - before/after blocks
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
 - Assertions
 - Matchers
 - before/after blocks

View testing:
Testing your code


Like Rails, RubyMotion comes bundled with ‘RSpec’ like framework ‘MacBacon’

    <motion_root>/spec/main_spec.rb
    $ rake spec




‘MacBacon’ has almost all ‘syntactic sugar’ that you are accustomed in RSpec:
 - Assertions
 - Matchers
 - before/after blocks

View testing:
 - Loading the nib/xib/storyboard file
Continuos Integration


              Jenkins setup on mac-mini          App Store


 WebHook                                  Push




Setup for local deployment and testing
Using External Libraries
Using External Libraries




RubyGems
Using External Libraries



                     Objective-C
RubyGems
                       Project
Using External Libraries



                      Objective-C
RubyGems
                        Project




Native-C
Using External Libraries



                      Objective-C
RubyGems
                        Project




Native-C              CocoaPods
RubyGems
RubyGems

Normal RubyGems won’t work
RubyGems

Normal RubyGems won’t work




Motion::Project::App.setup do |app|
  # Load files from gem
end
RubyGems

Normal RubyGems won’t work




Motion::Project::App.setup do |app|
  # Load files from gem
end




Use Bundler
RubyGems

Normal RubyGems won’t work




Motion::Project::App.setup do |app|
  # Load files from gem
end




                                 source :rubygems

                                 gem 'rake'               require ‘bundler’
Use Bundler                      gem 'bubble-wrap'        Bundler.require
                                 gem 'motion-cocoapods'
                                 gem 'motion-redgreen'           Rakefile
                                         Gemfile
RubyGems contd...
RubyGems contd...
Bubblewrap

teacup

sugarcube

formotion

Nitron

motion-redgreen

motion-logger

MotionModel

NativeJSBridge

SegmentTab
Using Obj-C code
Using Obj-C code

Statically Compiled

 app.vendor_project(
   “vendor/project-name”, #should have both .h and .m file
   :static
 )
Using Obj-C code

Statically Compiled

 app.vendor_project(
   “vendor/project-name”, #should have both .h and .m file
   :static
 )
Using Obj-C code

Statically Compiled

 app.vendor_project(
   “vendor/project-name”, #should have both .h and .m file
   :static
 )

XCode project:

  app.vendor_project(
   “vendor/project-name”,
   :xcode,
   :xcodeproj => “project-name.xcodeproj”,
   :target => “project-name”,
   :products => [“libproject-name.a”],
   :headers_dir => “project-name”
 )
Using native C code
Using native C code

         Basic Types in C                            Ruby data types

(bool, char, int, long, float, double)       (true/false, Fixnum, Bignum, Float)
Using native C code

         Basic Types in C                            Ruby data types

(bool, char, int, long, float, double)       (true/false, Fixnum, Bignum, Float)




  C Complex Data Structures
Using native C code

         Basic Types in C                            Ruby data types

(bool, char, int, long, float, double)       (true/false, Fixnum, Bignum, Float)




                                            No corresponding Ruby Data
  C Complex Data Structures
                                            Types
Using native C code

         Basic Types in C                            Ruby data types

(bool, char, int, long, float, double)       (true/false, Fixnum, Bignum, Float)




                                            No corresponding Ruby Data
                                            Types




  C Complex Data Structures
Using native C code

         Basic Types in C                                        Ruby data types

(bool, char, int, long, float, double)                   (true/false, Fixnum, Bignum, Float)




                                                        No corresponding Ruby Data
                                                        Types




  C Complex Data Structures
                                        BridgeSupport
Using native C code

         Basic Types in C                                        Ruby data types

(bool, char, int, long, float, double)                   (true/false, Fixnum, Bignum, Float)




                                                        No corresponding Ruby Data
                                                        Types




  C Complex Data Structures                                        RubyMotion
                                        BridgeSupport
CocoaPods
CocoaPods
is a dependency manager for Obj-C projects
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
pod setup # this may not be required for everyone, it never worked for me
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
pod setup # this may not be required for everyone, it never worked for me

https://github.com/CocoaPods/Specs - lists all the pods
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
pod setup # this may not be required for everyone, it never worked for me

https://github.com/CocoaPods/Specs - lists all the pods


It has been integrated with RubyMotion which comes as a gem
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
pod setup # this may not be required for everyone, it never worked for me

https://github.com/CocoaPods/Specs - lists all the pods


It has been integrated with RubyMotion which comes as a gem


sudo gem install motion-cocoapods
CocoaPods
is a dependency manager for Obj-C projects

sudo gem install cocoapods
pod setup # this may not be required for everyone, it never worked for me

https://github.com/CocoaPods/Specs - lists all the pods


It has been integrated with RubyMotion which comes as a gem


sudo gem install motion-cocoapods

Include it in your Rakefile:
require ‘moion-cocoapods’
Motion::Project::App.setup do |app|
 # ...
 app.pods do
  dependency 'JSONKit'
  dependency 'iActiveRecord'
 end
end
Long way to go !
Long way to go !



RM is only ~4 months old
Long way to go !



RM is only ~4 months old




Something it lacks:

 - Debugger (but REPL kind of makes it easy)
 - Some dynamic code doesn’t work (but hey !!!)
RM applications on AppStore
RM applications on AppStore


Everclip
RM applications on AppStore


Everclip

Cabify
RM applications on AppStore


Everclip

Cabify




Survey
RM applications on AppStore


Everclip

Cabify




Survey

http://signup.bigdayreminder.com/
RM applications on AppStore


Everclip

Cabify




Survey

http://signup.bigdayreminder.com/

http://jukely.com/
THANK YOU
One more thing !


15% discount
 toamitkumar@gmail.com

Ruby'izing iOS development