RubyConf AU 2013
Using Ruby for iOS development (RubyMotion)

Summarized using AI

Using Ruby for iOS development (RubyMotion)

Amit Kumar • February 20, 2013 • Earth

The video, titled "Using Ruby for iOS development (RubyMotion)," features Amit Kumar discussing how RubyMotion has transformed native app development for iOS devices at RubyConf AU 2013. He starts by introducing RubyMotion, a tool that allows developers to build iOS applications using Ruby, which many find less complex than Objective-C. Key points covered in the talk include:

  • Introduction to RubyMotion: RubyMotion combines Ruby with Objective-C by re-implementing the Ruby runtime on top of the Objective-C runtime, allowing seamless use of Cocoa's capabilities.
  • Static Compilation: RubyMotion utilizes LLVM technology to compile Ruby code into optimized machine code, ensuring high performance without overhead.
  • Integration with Cocoa: RubyMotion allows direct use of Objective-C classes as Ruby classes, enabling Ruby developers to leverage existing libraries and frameworks easily.
  • Testing and Development Workflow: Amit discusses the ease of writing tests with the MacBacon framework, utilizing commands like 'rake spec' and the importance of code signing for App Store submissions.
  • Command-line Control: The power of controlling the development environment via the command line using REPL (Read-Eval-Print Loop) was illustrated, showcasing real-time changes in the application.
  • RubyMotion's Features: Support for metaprogramming, usage of Ruby gems (with some restrictions), and the ability to work with Interface Builder were discussed as enhancements that improve developer productivity.
  • Community Contributions: The talk highlights community libraries such as BubbleWrap and Pix8 that simplify calling Objective-C methods in Ruby and allow CSS-like styling of iOS elements.
  • Dependency Management: Amit explains how to use CocoaPods to manage dependencies efficiently within RubyMotion projects.

In conclusion, Amit emphasizes that RubyMotion reduces complexity and enhances developer happiness when creating native iOS applications. He encourages the usage of RubyMotion for its robust features and community support, making it a worthwhile investment for developers looking to build iOS apps using Ruby.

Using Ruby for iOS development (RubyMotion)
Amit Kumar • February 20, 2013 • Earth

RubyConf AU 2013: http://www.rubyconf.org.au

RubyMotion has revolutionized native apps development platform for iOS devices. I would like to share some best practices/lessons learnt building apps using RubyMotion. This includes but not limited to:
What is RubyMotion
REPL
Using Obj-C, native C, gems in your RubyMotion application
Using storyboard
DSL for views
ActiveRecord-like ORM for iOS
Testing storyboard interface (Rspec and TestUnit)
CocoaPods
Dependency Management
Creating Gems
XCode integration
Continuous Integration
Releasing to AppStore
and others

RubyConf AU 2013

00:00:03.200 How is everyone doing? Having fun? It's been an incredible conference with great people, lots of good talks, and good food. One thing that could make this conference even better is beer!
00:00:20.240 I'm here to talk about using Ruby for building native iOS apps. Before I dive into that, let me quickly introduce myself. My name is Amit Kumar and I work for McKinsey. I would also like to do a quick survey of the crowd.
00:00:38.079 How many of you are Objective-C developers? Please keep your hands up. And how many of you love Objective-C? It’s a very good language, but when I started two years ago on a project that required a native iOS app, I tried learning Objective-C and found it quite challenging.
00:01:04.239 Although Objective-C is a robust language, my experience wasn't ideal. As a Ruby developer, the complexity of Objective-C code made my brain hurt. But then, late last summer, Laurent Sansonetti, the creator of MacRuby, launched RubyMotion.
00:01:30.240 RubyMotion helps you build native iOS apps using Ruby, which is an incredible and famous programming language. Let me explain what RubyMotion is: Laurent defines it as a revolutionary toolchain for building native iOS apps. I see it as a triumph of utilitarianism that reduces suffering.
00:01:59.759 Throughout this session, we'll explore how RubyMotion reduces suffering for developers and highlights moments of happiness we can experience. As we progress, please keep track of those moments.
00:02:29.440 Most of you are likely familiar with Ruby and MacRuby. Laurent focused on MacRuby and re-implemented the entire Ruby runtime that sits atop the Objective-C runtime. This integration allows for the seamless use of all constructs and capabilities within the Objective-C Cocoa framework.
00:02:55.120 It employs LLVM technology to statically compile Ruby code, which can then be deployed on your iOS device. Essentially, the Ruby code is turned into optimized machine code specific to the processor architecture.
00:03:19.680 This integration gives you the flexibility to use all Objective-C classes directly in your Ruby code as if they were Ruby classes. Moreover, you can share objects between Ruby and Objective-C without any performance cost, unlike bridge solutions such as PhoneGap or Mono.
00:03:42.959 A key feature of RubyMotion is that you write your code in Ruby, yet it gets compiled into machine code that your iOS device can understand, much like Objective-C. For example, if you look at the String class, the ancestors of the Objective-C NSMutableString class are the same as those of Ruby’s String class.
00:04:28.640 Let’s look at an example of inheritance and mixins in RubyMotion. The MyView class actually inherits from UIView, which is an Objective-C class, allowing for direct use without any performance overhead.
00:05:05.120 As Ruby developers, we appreciate the constructs supported in RubyMotion. Another construct we love is blocks. In RubyMotion, you can pass blocks around easily. For instance, when calling the animateWithDuration method from Objective-C's Cocoa framework, you can pass a block as an argument.
00:05:30.960 This showcases the signature of the method, which Objective-C developers will recognize. Initially, I found it challenging to understand why Objective-C uses named parameters, but I eventually appreciated their importance.
00:06:20.720 In RubyMotion, you can also use blocks within methods, as I demonstrated in some code I've been working on for chart visualizations using Core Plot, an Objective-C library.
00:06:58.240 RubyMotion supports many metaprogramming concepts we love in Ruby, such as define_method, method_missing, and instance_eval. However, one feature that RubyMotion does not support is the require method. This is due to the static compilation—RubyMotion needs to know in advance all the files your application will utilize.
00:07:39.120 Unfortunately, dynamic loading of files is not allowed because Apple does not permit interpreters to be shipped to iOS devices. Though some features are absent, for me, it doesn't significantly affect my work.
00:08:02.720 Now, how do you get started with RubyMotion? It’s a licensed product and, unfortunately, there is no trial version. However, I assure you it’s worth the investment. After purchasing, you can easily create your first application using the motion command.
00:08:47.440 Simply use 'motion create' followed by the name of your application to create its skeleton. This command automatically generates a rake file that contains all the configuration options for your application.
00:09:31.440 The main entry point for Cocoa framework applications is the AppDelegate class, which RubyMotion generates by default. Additionally, RubyMotion uses a framework called MacBacon to facilitate testing.
00:10:11.680 You can run tests simply by executing 'rake spec', which will run all defined test cases.
00:10:48.480 When you're ready to run your application, navigate to the root directory and execute the 'rake' command. The build system compiles the application files based on the definitions made in the rake file, links any external libraries, and launches the iOS simulator with your application.
00:11:41.600 The build process involves static compilation and linking the external libraries, which are packaged together. Additionally, a crucial step is code signing, required to submit your app to the App Store.
00:12:17.840 RubyMotion comprises three components: the runtime, the compiler, and the build system. The good news is that the build system has been open-sourced, and many contributions have been made by the Ruby community.
00:12:50.240 Executing 'rake tasks' will display various available options. Among these, 'rake' compiles your application, while 'rake spec' runs your test cases. 'rake clean' deletes all compiled files and rebuilds the application. The 'rake archive development' command helps you create an IPA file to test on your device, whereas 'rake archive release' optimizes the output for submission to the App Store.
00:13:39.800 Another recent addition is 'rake static,' which allows you to create a static library in RubyMotion. This library can then be imported into your Xcode projects, granting you the ability to utilize Ruby code within Objective-C applications.
00:14:02.720 The 'rake config' command reveals configuration options relevant when you first start learning RubyMotion, such as the build directory, the default AppDelegate class, and the deployment target for your application.
00:14:40.000 One highlight is the ability to control everything from the command line using REPL, even building your interface and code. I will demonstrate this now.
00:15:18.800 After running the rake command, the simulator should pop up, even though it was just a blank application initially. I'll grab the instance of a controller from the command line to make changes to the view.
00:16:21.440 Let's change the background color of the view to white. As I make modifications, I'll be adding a UILabel control with specific text to see dynamic changes reflected in real-time.
00:17:34.000 This ability to manipulate the application from the command line is incredibly powerful. Did we keep count of the moments of happiness? Please feel free to ask questions!
00:18:45.440 As an aside, Objective-C conventions like using 'alloc' versus 'new' are interchangeable. However, I prefer using 'alloc' when calling Objective-C classes as I'm unsure of what internal processes might be occurring.
00:19:28.160 A recent addition to RubyMotion is improved debugging that uses GDB technology, allowing for an easier debugging process right from the command line or IDE.
00:20:14.880 RubyMotion supports using external libraries, including Ruby gems. However, not all Ruby gems work due to the lack of the require method for dynamic loading; you can only use RubyMotion-compatible gems.
00:21:29.480 Notable contributions from the Ruby community include various RubyMotion wrappers and DSLS. One particularly impactful library is BubbleWrap, making it easier to call Objective-C from Ruby.
00:22:29.440 Another exciting option is Pix8, which allows you to style iOS controls using CSS. This development is significant for web developers looking to leverage existing skills while developing mobile applications.
00:23:30.960 Using CocoaPods, which is a dependency manager for Objective-C, you can easily incorporate existing Objective-C libraries into your RubyMotion projects.
00:24:29.280 Although you can utilize native C in RubyMotion, there are specific mappings you need for basic data types. Also, using complex data structures requires bridge support, which comes pre-installed.
00:25:30.000 Another great feature in RubyMotion is its capability to work with Interface Builder. You can design your app's interface using Apple's interface builder, and then RubyMotion will load the storyboard or nib files into your application.
00:26:13.200 Testing is crucial in software development. RubyMotion comes with a framework called MacBacon that allows you to write tests using syntax familiar to RSpec users.
00:27:25.760 API documentation was developed by the community, providing substantial resources on Objective-C classes and their Ruby equivalents, which is immensely helpful for RubyMotion developers.
00:28:16.960 Thank you for your attention! I'm happy to take any questions.
Explore all talks recorded at RubyConf AU 2013
+25