38
MY ADVENTURES IN OBJECTIVE-C @abdels / @thesupertimes

My Adventures In Objective-C (A Rubyists Perspective)

  • Upload
    abdels

  • View
    1.084

  • Download
    0

Embed Size (px)

Citation preview

Page 1: My Adventures In Objective-C (A Rubyists Perspective)

MY ADVENTURES IN OBJECTIVE-C

@abdels / @thesupertimes

Page 2: My Adventures In Objective-C (A Rubyists Perspective)

Objective-C sucks!

Page 3: My Adventures In Objective-C (A Rubyists Perspective)

Its just as crappy as Java!

Page 4: My Adventures In Objective-C (A Rubyists Perspective)

I’m waiting for MacRuby!

Page 5: My Adventures In Objective-C (A Rubyists Perspective)

OH NO!!

Page 6: My Adventures In Objective-C (A Rubyists Perspective)

still no iOS support, Boll@@ks!

Page 7: My Adventures In Objective-C (A Rubyists Perspective)

Objective-C Haters!

Page 8: My Adventures In Objective-C (A Rubyists Perspective)

Solutions

Page 9: My Adventures In Objective-C (A Rubyists Perspective)

PhoneGap

Page 10: My Adventures In Objective-C (A Rubyists Perspective)

Titanium Appcelerator

Page 11: My Adventures In Objective-C (A Rubyists Perspective)

But really, why all the hating?

Page 12: My Adventures In Objective-C (A Rubyists Perspective)

That’s pride f**king with you. F**k pride. Pride only hurts. It never helps. You fight

through that sh*t!

Page 13: My Adventures In Objective-C (A Rubyists Perspective)
Page 14: My Adventures In Objective-C (A Rubyists Perspective)

So, here's what I Learnt,

Page 15: My Adventures In Objective-C (A Rubyists Perspective)

SMALL TALK GUY (ALAN KAY)

Page 16: My Adventures In Objective-C (A Rubyists Perspective)

Objective-C, is reflective, OO, Smalltalk-ish!

Page 17: My Adventures In Objective-C (A Rubyists Perspective)

Sound a lot like Ruby

Page 18: My Adventures In Objective-C (A Rubyists Perspective)

Unlike Ruby, Objective-C is a strict superset of C

Page 19: My Adventures In Objective-C (A Rubyists Perspective)

Object Message passing :

[world say:@"hello"];

Obj-C

world.say("hello")

Ruby

Page 20: My Adventures In Objective-C (A Rubyists Perspective)

Object Message passing :

[world say:@"hello"];

Obj-C

[world performSelector:@selector(say:) withObject:@"hello"]

objc_sendMsg(id object, SEL selector)

Page 21: My Adventures In Objective-C (A Rubyists Perspective)

Object Message passing :

world.send(:say, "hello")

Ruby

Page 22: My Adventures In Objective-C (A Rubyists Perspective)

Non-strict typing (Duck Typing?)

id world = [[World alloc] init];

Obj-C

[world peace];

Here 'id' is a pointer to any object.

Page 23: My Adventures In Objective-C (A Rubyists Perspective)

Non-strict typing (Duck Typing?)

World *world = [[World alloc] init];

Obj-C

[world peace];

This ensures method compiler checks!

Page 24: My Adventures In Objective-C (A Rubyists Perspective)

Object declaration

MyClass * myObject = [[MyClass alloc] init];

Obj-C

class Object def self.new(*args) self.alloc.initialize(*args) endend

Ruby (pseudo code)

Page 25: My Adventures In Objective-C (A Rubyists Perspective)

Interface/Implementation (the C thing)

world.h (header file)#import <UIKit/UIKit.h>

@interface World : NSObject { NSString *foo;}

@property (copy, retain) NSString *foo; -(NSString *) say:(NSString *)something;@end

Page 26: My Adventures In Objective-C (A Rubyists Perspective)

Interface/Implementation (the C thing)world.m (implementation file)#import "world.h"

@implementation World@synthesize foo;

-(NSString *) say:(NSString *)something{}

- (void)dealloc { [foo release]; [super dealloc];}@end

Page 27: My Adventures In Objective-C (A Rubyists Perspective)

Properties aka attr_accessor@interface World : NSObject { NSString *foo; ... @property (copy, retain) NSString *foo; ...@end

@implementation World@synthesize foo;...@end

Page 28: My Adventures In Objective-C (A Rubyists Perspective)

Properties aka attr_accessor

-(void)setFoo:(Foo *)s { if(foo != s) { [foo release]; foo = [s retain]; }}

-(Foo *)foo { return foo; }

@synthesize: creates dynamic setters and getters and performs the necessary memory allocation.

Page 29: My Adventures In Objective-C (A Rubyists Perspective)

Interfaces with Protocols@protocol Shopper- (void)recession;- (void)boom;@end

@interface World : NSObject <Shopper>@end

Page 30: My Adventures In Objective-C (A Rubyists Perspective)

Monkey Patching with Categories

UIImage+RoundedCorner.h@interface UIImage (RoundedCorner)- (UIImage *)roundedCornerImage;@end

UIImage+RoundedCorner.m@implementation UIImage (RoundedCorner)- (UIImage *)roundedCornerImage { //Make rounded corners}@end

Page 31: My Adventures In Objective-C (A Rubyists Perspective)

We Have Blocks!

NSArray *films = [NSArray arrayWithObjects:@"Reservoir Dogs", @"Pulp Fiction", @"Kill Bill", nil]; [films enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) { NSLog(@"%@ film at index %d", object, index);}];

Page 32: My Adventures In Objective-C (A Rubyists Perspective)

We Have Blocks!

int (^negative)(int) = ^(int number) { return number * -1;};

int result = negative(2);

Page 33: My Adventures In Objective-C (A Rubyists Perspective)

Basics over

Page 34: My Adventures In Objective-C (A Rubyists Perspective)

You panicked, but don’t

Page 35: My Adventures In Objective-C (A Rubyists Perspective)

iOS is a powerful platform that controls phones

Page 36: My Adventures In Objective-C (A Rubyists Perspective)

Your brain & eyes hurting is a small price to pay for the privelage :P

Page 38: My Adventures In Objective-C (A Rubyists Perspective)

@abdels / @thesupertimes