Share
Embed
Rubymotion
Charla de rubymotion para meetup dynlang chile, 2013
Miguel Michelson Martinez
July 17, 2013
Transcript
65 slides
-
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 -
RUBY Lenguaje OOP Permite metaprogramar sintaxis muy expresiva facil de
usar y extender Monday, September 2, 13 -
RUBY https://github.com/cogitator/ruby- implementations/wiki/List-of-Ruby- implementations IRONRUBY / JRUBY / MACRUBY /
MRUBY Monday, September 2, 13 -
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 -
OBJ-C Class Implementation @implementation classname +classMethod { // implementation }
-instanceMethod { // implementation } @end .m Monday, September 2, 13 -
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 -
OBJ-C Object Instanciation MyObject * o = [[MyObject alloc] init];
allocation intialization Monday, September 2, 13 -
OBJ-C/COCOA Cocoa/Cocoa Touch object-oriented application programming interface Foundation Kit Application
Kit / UIKit CoreData Frameworks Monday, September 2, 13 -
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 -
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 -
RubyMotion Requirements RubyMotion requires a Mac Install the iOS and
OS X SDK Monday, September 2, 13 -
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 -
RubyMotion Hello World alert = UIAlertView.new alert.message = "Hello World!"
alert.show $ motion create hello_world Monday, September 2, 13 -
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 -
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 -
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 -
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 -
RubyMotion Pointers rect_ptr = Pointer.new(CGRect.type) rect_ptr = Pointer.new(:int) C type
pointer Structure pointers Monday, September 2, 13 -
RubyMotion OBJ-C VS RUBYMOTION arr = ["uno", "dos", "tres"] NSMutableArray
*myColors; myColors = [NSMutableArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil]; Monday, September 2, 13 -
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 -
RubyMotion OBJ-C VS RUBYMOTION “Hello” + “world” NSString *string =
[NSString stringWithFormat:@"%@%@", @"Hello", @"World"]; NSLog(@"%@", string); Monday, September 2, 13 -
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 -
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 -
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 -
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 -
RubyMotion app.pods do pod 'NanoStore' #, '~> 2.1.4' #pod 'NUI'
pod 'SVProgressHUD' pod 'SDWebImage' end CocoaPods Monday, September 2, 13 -
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 -
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 -
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