Ruby Motion

IOS with the Power of Ruby

Aaron Renner / @bayfieldcoder
Animas Code Labs

Why it's Cool

  • Harness power of Ruby
  • Can use Objective-C directly
  • Do more with less
  • Wrappers

How it works


Power of Ruby

Objective C

NSMutableArray *arr = [NSMutableArray withObjects:@"Durango",@"Bayfield", nil];
[arr addObject:@"Pagosa Springs"]

NSArray *sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

Ruby

(main)> arr = ["Durango", "Bayfield"]
=> ["Durango", "Bayfield"]
(main)> arr << "Pagosa Springs"
=> ["Durango", "Bayfield", "Pagosa Springs"]
(main)> arr.sort
=> ["Bayfield", "Durango", "Pagosa Springs"]

How it Translates

      
        (main)> "Hello World".class.ancestors
        => [String, NSMutableString, NSString, Comparable, NSObject, Kernel]
        (main)> ["Durango", "Bayfield"].class.ancestors
        => [Array, NSMutableArray, NSArray, Enumerable, NSObject, Kernel]
      
    

Objective C to Ruby

Objective C

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Durango Coders"
                                        message:@"Welcome to ObjectiveC"
                                        delegate:nil
                                        cancelButtonTitle:@"Let's Code"
                                        otherButtonTitles: nil];
    [alert show];

    return YES;
}@end

Objective C to Ruby

Ruby

 class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @alert = UIAlertView.alloc.initWithTitle("Durango Coders",
                                   message: "Welcome to Ruby Motion",
                                   delegate: nil,
                                   cancelButtonTitle: "Let's Code",
                                   otherButtonTitles: nil)
    @alert.show
    true
  end
end

Wrappers

http://rubymotion-wrappers.com/

  • BubbleWrap
  • IB
  • Sugarcube
  • Promotion

Let's Code!

UITableViewController

UITableViewController

- (NSInteger)tableView:(UITableView *)tableView 
        numberOfRowsInSection:(NSInteger)section {
    return self.booksArray.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.textLabel.text = [self.booksArray objectAtIndex:indexPath.row];
    return cell;
}

Deployment

Add the following to your rake file

app.identifier = "com.animascodelabs.durango_coders"
app.provisioning_profile = "~/Library/MobileDevice/Provisioning Profiles/<uuid>.mobileprovision"
app.code_sign_certificate = "iPhone Developer: <Your name>"

Beta Testing

testflightapp.com

gem "motion-testflight"

Resources

Thank You

Questions?

aaron@animascodelabs.com

@bayfieldcoder | Github