The document discusses the speaker's experience transitioning from Ruby to Objective-C for iOS app development. Some key points of comparison between the two languages are their object-oriented nature, use of messages and blocks, and common ancestry in Smalltalk. The speaker notes advantages of Ruby's ecosystem with Rails but also that Cocoa is the more difficult part of iOS development versus Objective-C itself. Overall, the experience of developing iOS apps draws from backgrounds in Ruby, C/C++, and Flash.
46. object model
dog = Dog.new
!
puts "class of dog is #{dog.class}”
# Dog
puts "superclass of dog is #{dog.class.superclass}” # Animal
puts "super superclass of dog is
#{dog.class.superclass.superclass}”
# Object
puts "super super superclass of dog is
#{dog.class.superclass.superclass.superclass}” # BasicObject
!
puts
puts
puts
puts
"class
"class
"class
"class
of Dog is #{Dog.class}”
class of Dog is #{Dog.class.class}”
of Animal is #{Animal.class}”
of Object is #{Object.class}”
#
#
#
#
Class
Class
Class
Class
47. object model
@interface Animal : NSObject
@end
!
@implementation Animal
@end
!
@interface Dog : Animal
@end
!
@implementation Dog
@end
48. object model
Dog* dog = [[Dog alloc] init];
!
NSLog(@"class of dog is %@", [dog class]); # Dog
!
NSLog(@"superclass of dog is %@", [dog superclass]); # Animal
!
NSLog(@"super superclass of dog is %@", [[dog superclass] superclass]); #
NSObject
!
NSLog(@"super super superclass of dog is %@", [[[dog superclass]
superclass] superclass]); # null
55. sending message
class Bank
def save(money)
puts "you just saved #{money} dollars"
end
end
!
bank = Bank.new
bank.save 20
bank.send(:save, 20)
# you just saved 20 dollars
# you just saved 20 dollars
56. sending message
@interface Bank : NSObject
- (void) save:(NSNumber *) money;
@end
!
@implementation Bank
- (void)save:(NSNumber *)money
{
NSLog(@"you just saved %@ dollars", money);
}
@end
!
Bank* bank = [[Bank alloc] init];
[bank save:@20];
[bank performSelector:@selector(save:) withObject:@20];
63. iteration
list = [1, 2, 3, 4, 5]
!
sum = 0
!
list.each { |num|
sum += num
}
!
puts "sum = #{sum}"
64. iteration
NSArray* list = @[@1, @2, @3, @4, @5];
!
__block int sum = 0;
!
[list enumerateObjectsUsingBlock:^(NSNumber* num,
NSUInteger idx, BOOL *stop) {
sum += [num intValue];
}];
!
NSLog(@"sum = %d", sum);
65. iteration
class Fox
def say
puts "what does the fox say?"
end
end
!
fox1 = Fox.new
fox2 = Fox.new
fox3 = Fox.new
foxes = [fox1, fox2, fox3]
!
foxes.map { |fox| fox.say }
# what does the fox say?
66. iteration
@interface Fox : NSObject
- (void) say;
@end
!
@implementation Fox
- (void) say
{
NSLog(@"what does the fox say?!");
}
@end
78. Objective-C : cocoapods
platform :ios, '6.0'
!
pod
pod
pod
pod
pod
pod
'Facebook-iOS-SDK', '~> 3.5.1’
'JSONKit', '~> 1.5pre'
'MagicalRecord', '~> 2.0.7’
'SSKeychain', '~> 0.1.4’
'TestFlightSDK', '~> 1.1'
'SMCalloutView', '~> 1.1.2'
!
target :UnitTests do
link_with 'UnitTests'
pod 'OCMock', '~> 2.0.1'
pod 'OCHamcrest', '~> 1.9'
end