| 1 | <h2>Full example</h2> |
| 2 | <pre><code>#import <UIKit/UIKit.h> |
| 3 | #import "Dependency.h" |
| 4 | |
| 5 | @protocol WorldDataSource |
| 6 | @optional |
| 7 | - (NSString*)worldName; |
| 8 | @required |
| 9 | - (BOOL)allowsToLive; |
| 10 | @end |
| 11 | |
| 12 | @interface Test : NSObject <HelloDelegate, WorldDataSource> { |
| 13 | NSString *_greeting; |
| 14 | } |
| 15 | |
| 16 | @property (nonatomic, readonly) NSString *greeting; |
| 17 | - (IBAction) show; |
| 18 | @end |
| 19 | |
| 20 | @implementation Test |
| 21 | |
| 22 | @synthesize test=_test; |
| 23 | |
| 24 | + (id) test { |
| 25 | return [self testWithGreeting:@"Hello, world!\nFoo bar!"]; |
| 26 | } |
| 27 | |
| 28 | + (id) testWithGreeting:(NSString*)greeting { |
| 29 | return [[[self alloc] initWithGreeting:greeting] autorelease]; |
| 30 | } |
| 31 | |
| 32 | - (id) initWithGreeting:(NSString*)greeting { |
| 33 | if ( (self = [super init]) ) { |
| 34 | _greeting = [greeting retain]; |
| 35 | } |
| 36 | return self; |
| 37 | } |
| 38 | |
| 39 | - (void) dealloc { |
| 40 | [_greeting release]; |
| 41 | [super dealloc]; |
| 42 | } |
| 43 | |
| 44 | @end</code></pre> |