21. Objective-C Primer
Defining Methods
Method name (selector)
-(void)showLoadingText:(NSString *)text animated:(BOOL)animated;
22. Objective-C Primer
Defining Methods
Method name (selector)
-(void)showLoadingText:(NSString *)text animated:(BOOL)animated;
Return Type
23. Objective-C Primer
Defining Methods
Method name (selector)
-(void)showLoadingText:(NSString *)text animated:(BOOL)animated;
Return Type
Instance method
24. Objective-C Primer
Defining Methods
Method name (selector)
-(void)showLoadingText:(NSString *)text animated:(BOOL)animated;
Return Type
Parameters
Instance method
25. Other interesting Things
nil is a no-op
Foo *foo = nil;
[foo doSomething]; //nothing happens
NSArray *array = nil;
[array count]; //returns 0
26. Other Interesting Things
Mix-in C style method definitions
// I put this in Macros.h
static inline BOOL isEmpty(id thing) {
return thing == nil
|| ([thing respondsToSelector:@selector(length)]
&& [(NSData *)thing length] == 0)
|| ([thing respondsToSelector:@selector(count)]
&& [(NSArray *)thing count] == 0);
}
this method comes from Wil Shipley
27. Other Interesting Things
Dynamic Programming achieved through Key-Value
Coding
NSArray *items = [NSArray arrayWithObject:foo];
[items valueForKey:@"count"]; //returns 1
28. Other Interesting Things
Can achieve "Extension Methods" or "Mix-ins" via
Objective-C Categories
//NSString+MyAdditions.h
@interface NSString (MyAdditions)
-(NSString *)stringInReverse;
@end
//NSString+MyAdditions.m
@implementation NSString (MyAdditions)
-(NSString *)stringInReverse { ... }
@end
//usage
#import "NSString+MyAdditions.h"
[@"foxy" stringInReverse]; //returns @"yxof"
74. Interface Builder
Now Part of Xcode 4
Drag-n-drop UI building
Layouts are defined in XIBs (XML representation).
Usually called "Nibs"
"Make connections" with classes defined in Xcode
variables --> UI components
UI events --> methods