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

Use RubyMotion

Use RubyMotion

Avatar for Brent Hargrave

Brent Hargrave

April 10, 2013
Tweet

Other Decks in Programming

Transcript

  1. How? •Language: more expressive •Configuration: not in Xcode •Editor: is

    not Xcode •Testing: baked-in Tuesday, May 21, 13
  2. AFNetworking NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation

    JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { // handle success } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { // handle failure }]; [operation start]; in Objective-C Tuesday, May 21, 13
  3. AFNetworking request = NSURLRequest.requestWithURL url operation = AFJSONRequestOperation.JSONRequestOperationWithRequest request, success:

    lambda { |request, response, id| # handle success }, failure: lambda { |request, response, error, id| # handle failure } operation.start straight Ruby port Tuesday, May 21, 13
  4. AFNetworking AFMotion::Operation::JSON.get("request/path") do |result| if result.success? # handle success elsif

    result.failure? # handle failure end end “authentic” Ruby port Tuesday, May 21, 13
  5. Ugh, Ruby performance? •RubyMotion’s Ruby != MRI •Compiled, not interpreted

    •Ruby => AST => LLVM IR => machine code Tuesday, May 21, 13
  6. Ruby inherits from Obj-C # kinda/sorta what's happening class String

    < NSString #... end rb_string = "foo" rb_string.methods.include? "capitalizedString" #=> true Tuesday, May 21, 13
  7. OK, so it’s fast. What about memory? ARC-like reference counting,

    not garbage collected. Tuesday, May 21, 13
  8. Configuration: Rake, not Xcode # -*- coding: utf-8 -*- $:.unshift("/Library/RubyMotion/lib")

    require 'motion/project' Motion::Project::App.setup do |app| # Use `rake config' to see complete project settings. app.name = 'sample_app' end Tuesday, May 21, 13
  9. RubyMotion & Xcode •Xcode artifacts can be used in RM

    •Storyboards •CoreData models Tuesday, May 21, 13
  10. RubyMotion & Xcode Motion::Project::App.setup do |app| # ... app.pods do

    pod "RestKit" pod "AFNetworking" end end Tuesday, May 21, 13
  11. RubyGems •Share RM code using gems •But few existing gems

    work! •No “eval” or “require” Tuesday, May 21, 13