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

Rubymotion

 Rubymotion

Charla de rubymotion para meetup dynlang chile, 2013

Transcript

  1. Laurent Sansonetti RUBYMOTION 7 Years at Apple as senior software

    engineer for iLife and OS X Creator and Mantainer of MacRuby RubyCocoa & Gnome contributor Monday, September 2, 13
  2. OBJ-C @interface classname : superclassname { // instance variables }

    +classMethod1; +(return_type)classMethod2; +(return_type)classMethod3:(param1_type)parameter_varName; -(return_type)Method1:(type1)param1_varName :(type2)param2_varName; -(return_type)Method2: (type1)varName1 otherParameter:(type2)varName2 @end Class Definition .h Monday, September 2, 13
  3. OBJ-C Class Implementation @implementation classname +classMethod { // implementation }

    -instanceMethod { // implementation } @end .m Monday, September 2, 13
  4. OBJ-C Method Declaration -(int)method:(int)i { return [self square_root: i]; }

    int function(int i) { return square_root(i); } C OBJ-C Monday, September 2, 13
  5. OBJ-C Object Instanciation MyObject * o = [[MyObject alloc] init];

    allocation intialization Monday, September 2, 13
  6. XCODE Hello World http://www.appcoda.com/hello-world-build-your-first-iphone-app/ UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello

    World!" message:@"orrait!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [message show]; Monday, September 2, 13
  7. RubyMotion RubyMotion apps are created and later maintained from the

    terminal command-line. A RubyMotion project is based on the Rake tool and can be configured by editing its Rakefile. Monday, September 2, 13
  8. RubyMotion Hello World class AppDelegate def application(application, didFinishLaunchingWithOptions:launchO alert =

    UIAlertView.new alert.message = "Hello World!" alert.show true end end $ motion create hello_world Monday, September 2, 13
  9. RubyMotion Hello World alert = UIAlertView.new alert.message = "Hello World!"

    alert.show $ motion create hello_world Monday, September 2, 13
  10. RubyMotion Object Model Ruby Model implemented from Objective-C runtime In

    RubyMotion, Ruby classes, methods and objects are Objective-C classes Objective-C classes, methods and objects are available in Ruby as if they were native. Monday, September 2, 13
  11. RubyMotion Object Model Objective-C and RubyMotion share the same object

    model infrastructure. Objective-C and RubyMotion APIs can be interchangeable at no additional performance expense. Monday, September 2, 13
  12. RubyMotion Interfacing with C Basic Types Basic C types cannot

    be created from Ruby directly, but are automatically converted from and to equivalent Ruby types. Monday, September 2, 13
  13. RubyMotion Structs pt = CGPoint.new pt.x = 100 pt.y =

    200 'Hello'.drawAtPoint(pt, withFont: font) #It is possible to pass the field values directly to the constructor. pt = CGPoint.new(100, 200) 'Hello'.drawAtPoint(pt, withFont: font) #RubyMotion will also accept arrays as a convenience. #They must contain the same number and type of objects expected in the structure. 'Hello'.drawAtPoint([100, 200], withFont: font) C structures are mapped to classes in RubyMotion. Monday, September 2, 13
  14. RubyMotion OBJ-C VS RUBYMOTION arr = ["uno", "dos", "tres"] NSMutableArray

    *myColors; myColors = [NSMutableArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil]; Monday, September 2, 13
  15. RubyMotion OBJ-C VS RUBYMOTION dict = {key: "value", key2: "dos",

    key3: "tres"} NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; Monday, September 2, 13
  16. RubyMotion OBJ-C VS RUBYMOTION “Hello” + “world” NSString *string =

    [NSString stringWithFormat:@"%@%@", @"Hello", @"World"]; NSLog(@"%@", string); Monday, September 2, 13
  17. RubyMotion OBJ-C VS RUBYMOTION 10 + “string” int numero =

    10; NSString = @string" bah NSString *string = @"string" NSString *stringConcat = [NSString stringWithFormat:@"%s - %i",string, numero]; Monday, September 2, 13
  18. RubyMotion OBJ-C VS RUBYMOTION //XYZPerson.h" @interface Person : NSObject @property

    NSString *firstName; @property NSString *lastName; @end //XYZPerson.m" #import "XYZPerson.h" @implementation XYZPerson - (void)fullName { NSLog(@"Hello, World!"); } @end class Person attr_accessor :first_name, :last_name def hello_world "#{@first_name} #{@last_name}" end end Monday, September 2, 13
  19. RubyMotion APP Configuration Motion::Project::App.setup do |app| # Use `rake config'

    to see complete project settings. app.name = 'delaymachine' app.device_family = :iphone app.icons = ["nucleardevilhorns.jpg"] app.frameworks += ['CoreImage', 'QuartzCore'] .... end Monday, September 2, 13
  20. RubyMotion Vendorize app.vendor_project('vendor/pd-for-ios/libpd', :xcode, :xcodeproj => 'libpd.xcodeproj', :target => 'libpd-ios',

    :headers_dir => 'objc' ) app.vendor_project('vendor/dccontrols', :static) Monday, September 2, 13
  21. RubyMotion app.pods do pod 'NanoStore' #, '~> 2.1.4' #pod 'NUI'

    pod 'SVProgressHUD' pod 'SDWebImage' end CocoaPods Monday, September 2, 13
  22. RubyMotion Bundler source "https://rubygems.org" gem "motion-cocoapods" gem 'bubble-wrap' gem "ProMotion"

    #gem "formotion" #gem "nitron" #gem "teacup" #gem "nano-store" #gem "elevate", "~> 0.5.0" #gem 'motion-config-vars' #gem "motion-hpple" group :development do gem 'guard-shell', :require=>false end Monday, September 2, 13
  23. RubyMotion Test describe "Application 'rubymotion-libpd'" do before do @app =

    UIApplication.sharedApplication end it "has one window" do @app.windows.size.should == 1 end end Monday, September 2, 13
  24. RubyMotion Promotion class AppDelegate < PM::Delegate def on_load(app, options) open

    RootScreen.new(nav_bar: true) end end class RootScreen < PM::Screen title "Root Screen" def push_new_screen open NewScreen end end class NewScreen < PM::TableScreen title "Table Screen" def table_data [{ cells: [ { title: "About this app", action: :tapped_about }, { title: "Log out", action: :log_out } ] }] end end Monday, September 2, 13