My Adventures In Objective-C (A Rubyists Perspective)

1,468 views

Published on

This is an introduction to Objective-C for Rubyists.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,468
On SlideShare
0
From Embeds
0
Number of Embeds
64
Actions
Shares
0
Downloads
6
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • My Adventures In Objective-C (A Rubyists Perspective)

    1. 1. MY ADVENTURES IN OBJECTIVE-C@abdels / @thesupertimes
    2. 2. Objective-C sucks!
    3. 3. Its just as crappy as Java!
    4. 4. I’m waiting for MacRuby!
    5. 5. OH NO!!
    6. 6. still no iOS support, Boll@@ks!
    7. 7. Objective-C Haters!
    8. 8. Solutions
    9. 9. PhoneGap
    10. 10. Titanium Appcelerator
    11. 11. But really, why all the hating?
    12. 12. That’s pride f**king with you. F**k pride.Pride only hurts. It never helps. You fight through that sh*t!
    13. 13. So, heres what I Learnt,
    14. 14. SMALL TALK GUY (ALAN KAY)
    15. 15. Objective-C, is reflective, OO, Smalltalk-ish!
    16. 16. Sound a lot like Ruby
    17. 17. Unlike Ruby,Objective-C is a strict superset of C
    18. 18. Object Message passing :Obj-C[world say:@"hello"];Rubyworld.say("hello")
    19. 19. Object Message passing :Obj-C[world say:@"hello"];[world performSelector:@selector(say:) withObject:@"hello"]objc_sendMsg(id object, SEL selector)
    20. 20. Object Message passing :Rubyworld.send(:say, "hello")
    21. 21. Non-strict typing (Duck Typing?)Obj-Cid world = [[World alloc] init];[world peace];Here id is a pointer to any object.
    22. 22. Non-strict typing (Duck Typing?)Obj-CWorld *world = [[World alloc] init];[world peace];This ensures method compiler checks!
    23. 23. Object declarationObj-CMyClass * myObject = [[MyClass alloc] init];Ruby (pseudo code)class Object def self.new(*args) self.alloc.initialize(*args) endend
    24. 24. 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
    25. 25. 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
    26. 26. Properties aka attr_accessor@interface World : NSObject { NSString *foo; ... @property (copy, retain) NSString *foo; ...@end@implementation World@synthesize foo;...@end
    27. 27. Properties aka attr_accessor@synthesize: creates dynamic setters and getters andperforms the necessary memory allocation.-(void)setFoo:(Foo *)s { if(foo != s) { [foo release]; foo = [s retain]; }}-(Foo *)foo { return foo; }
    28. 28. Interfaces with Protocols@protocol Shopper- (void)recession;- (void)boom;@end@interface World : NSObject <Shopper>@end
    29. 29. Monkey Patching with CategoriesUIImage+RoundedCorner.h@interface UIImage (RoundedCorner)- (UIImage *)roundedCornerImage;@endUIImage+RoundedCorner.m@implementation UIImage(RoundedCorner)- (UIImage *)roundedCornerImage { //Make rounded corners}@end
    30. 30. We Have Blocks!NSArray *films = [NSArray arrayWithObjects:@"ReservoirDogs", @"Pulp Fiction", @"Kill Bill", nil];[films enumerateObjectsUsingBlock:^(id object, NSUIntegerindex, BOOL *stop) { NSLog(@"%@ film at index %d", object, index);}];
    31. 31. We Have Blocks!int (^negative)(int) = ^(int number) { return number * -1;};int result = negative(2);
    32. 32. Basics over
    33. 33. You panicked, but don’t
    34. 34. iOS is a powerful platform that controls phones
    35. 35. Your brain & eyes hurting is a small price to pay for the privelage :P
    36. 36. REFERENCES HTTP://EN.WIKIPEDIA.ORG/WIKI/OBJECTIVE-C HTTP://EN.WIKIPEDIA.ORG/WIKI/MACRUBY HTTP://OFPS.OREILLY.COM/TITLES/9781449380373/INDEX.HTML HTTP://BLOG.PHUSION.NL/2010/03/24/OBJECTIVE-C-FOR-RUBY-DEVELOPERS- UN-NOT-SO-PETIT-INTERLUDE-1/ HTTP://GOSHAKKK.NAME/BLOG/2011/08/19/OBJECTIVE-C-RUBYISTS-INSIGHT/ HTTP://GOOGLE-STYLEGUIDE.GOOGLECODE.COM/SVN/TRUNK/ OBJCGUIDE.XML
    37. 37. @abdels / @thesupertimes

    ×