Professional Documents
Culture Documents
• Strongly typed
object.method(param)
=
[object method:param];
person.set_name(“john”, “doe”)
[person setNameWithFirst:@”john”
withLast:@”doe”];
array = []
=
NSMutableArray *array =
[[NSMutableArray alloc] init];
“ string”.strip
=
[@“ string” stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]]
=
NSArray *keys = [NSArray arrayWithObjects:@”key1”,@”key2”];
NSArray *data = [NSArray arrayWithObjects:@”value1”,@”value2”];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
setObject_forKey_(iphone, phone)
[setObject:iphone forKey:phone];
• Performance
• Two runtimes
• Object conversions
• Replacing RubyCocoa
• HotCocoa Support
Wednesday, December 1, 2010
MAC
RUBY
Object NSObject
String NSMutableString
Number NSNumber
Array NSMutableArray
Hash NSMutableDictionary
Objects Objective-C
Classes Objective-C
Methods Objective-C
>> s.class
=> NSMutableString
>> s.class.ancestors
=> [NSMutableString,NSString,Comparable,NSObject,Kernel]
>> s.upcase
=> “RUBYCONF”
>> s.uppercaseString
=> “RUBYCONF”
>> NSString.stringWithString(“rubyconf”)
=> “rubyconf”
>> NSString.alloc.initWithString(“rubyconf”)
=> “rubyconf”
>> a.class
=> NSMutableArray
>> a.class.ancestors
=> [NSMutableArray,NSArray,Enumerable,NSObject,Kernel]
>> locationManager(manager
didUpdateToLocation:newLocation,
fromLocation:oldLocation)
>> locationManager(manager
:didUpdateToLocation => newLocation,
:fromLocation => oldLocation)
attr_accessor :my_string
=
# Interface (header file)
NSString *myString;
@property(nonatomic,retain) IBOutlet NSString *myString;
def my_action(sender)
...
end
=
# Interface
-(IBAction) myAction:(id)sender;
# Implementation
-(IBAction) myAction:(id)sender { ... }
Xcode
Interface Builder
Instruments
• Test::Unit
• RSpec
• Cucumber
• etc...