25
Introduction to RubyMotion The Cool Way to Build iOS Apps By Gant Laborde

Introduction to RubyMotion - The Cool Way to Build iOS Apps

Embed Size (px)

DESCRIPTION

Introduction to RubyMotion by Gant Laborde - 2013 Live Presentation Link - http://gantman.github.io/RubyMotion-Intro/ Presentation Code - https://github.com/GantMan/RubyMotion-Intro

Citation preview

Page 1: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Introduction to RubyMotion

The Cool Way to Build iOS Apps

By Gant Laborde

Page 2: Introduction to RubyMotion - The Cool Way to Build iOS Apps

@GantLabordeAvid Rubyist and generally immature guy

Co-Founder of IconoclastLabs.com

Page 3: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Author of Numerous RubyMotion projects and Pull Requests

Author of the book RubyMotion App Development by Packt Publishing.

Page 4: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Motion Meetup OrganizerRubyMotion's Monthly Meetup

meetup.RubyMotion.com

Page 5: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Matt Garrison

@mattsgarrison

Page 6: Introduction to RubyMotion - The Cool Way to Build iOS Apps

RubyMotion

Page 7: Introduction to RubyMotion - The Cool Way to Build iOS Apps

RubyMotion - Wat?

/ˈroo͞bē-mōSHən/

noun trademark 1. A proprietary toolchain, created by HipByte SPRL, for

developing native iOS and OS X applications on Apple devicesand computers by statically compiling the Ruby programming

language.OR

Apps the Ruby Way

Page 8: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Quick ExampleObjective-C button tap

[button addTarget:self action:@selector(buttonTapped:) forControlEvents: UIControlEventTouchUpInside];

// Elsewhere - (void)buttonTapped:(id)sender { self.view.backgroundColor = [UIColor redColor]; }

RubyMotion button tap

button.addTarget(self, action:'button_tapped', forControlEvents:UIControlEventTouchUpInside)

# Elsewhere def button_tapped self.view.backgroundColor = UIColor.redColor end

Page 9: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Better ExampleObjective-C button tap

[button addTarget:self action:@selector(buttonTapped:) forControlEvents: UIControlEventTouchUpInside];

// Elsewhere

- (void)buttonTapped:(id)sender { self.view.backgroundColor = [UIColor redColor]; }

RubyMotion button tap (with sugarcube gem)

button.on(:touch) do self.view.backgroundColor = :red.uicolor end

Page 10: Introduction to RubyMotion - The Cool Way to Build iOS Apps

and more like_rubylessLike:objectiveC:

- Clay Allsopp

Page 11: Introduction to RubyMotion - The Cool Way to Build iOS Apps

What's So Great About RubyMotion?In my opinion

Gems and CommunityEditor IndependenceTesting!ReadabilityNatively CompiledThe REPL

Page 12: Introduction to RubyMotion - The Cool Way to Build iOS Apps

RubyMotion AnalogyRubyMotion is to Objective-C

As Coffeescript is to Javascript

... plus gems are kind of like jQuery plugins

... plus MacBacon has spec tests like Jasmine would

... plus the REPL lets you live-modify like developer tools

... plus it compiles and obfuscates your final codebase

... OK, this analogy got out of control

Page 13: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Let's Look At Code!Classic - Hello World

Full App - Ruby Trivia

Games!

Page 14: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Hello World

$ motion create test

Tests will fail

class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.rootViewController = HelloWorldController.new @window.makeKeyAndVisible true end end

class HelloWorldController < UIViewController def viewDidLoad p "Hai" end end

Now tests pass!

Page 15: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Hello World - REPL

main_view = UIApplication.sharedApplication.windows[0].rootViewController.view

main_view.backgroundColor = UIColor.blueColor

OR, just command click the view!

# REPL input

self.backgroundColor = UIColor.whiteColor

@label = UILabel.new

@label.text = "Hello World"

@label.sizeToFit

self.addSubview(@label)

# get down from there!

@label.center = [100, 100]

OR, use sugarcube-repl's tree command.

Page 16: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Code Example #2Ruby TriviasugarcubeTeacupProMotionBubbleWrapformotionand more ...

Page 17: Introduction to RubyMotion - The Cool Way to Build iOS Apps

iconoclastlabs.github.io/rubytrivia/

Page 18: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Available on itunes

Page 19: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Let's look at the code!

Page 20: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Code Example #3Joybox

Page 21: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Joyboxjoybox.io

Based on Cocos2DIncludes Box2D physicsWrapped in Ruby API

EASY

Page 22: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Joybox

Page 23: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Let's look at some Joybox code!

2:51

Page 24: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Totally Tacos!A game made in one day!

Page 25: Introduction to RubyMotion - The Cool Way to Build iOS Apps

Thank you!Questions?

@GantLaborde

Feel free to contact me via [email protected]