1 #import <Foundation/Foundation.h> 2 3 @protocol MyProtocol 4 5 -(const char *)hello; 6 7 @end 8 9 @interface BaseClass : NSObject 10 { 11 int _backedInt; 12 int _access_count; 13 } 14 15 - (int) nonexistantInt; 16 - (void) setNonexistantInt: (int) in_int; 17 18 - (int) myGetUnbackedInt; 19 - (void) mySetUnbackedInt: (int) in_int; 20 21 - (int) getAccessCount; 22 23 +(BaseClass *) baseClassWithBackedInt: (int) inInt andUnbackedInt: (int) inOtherInt; 24 25 @property(getter=myGetUnbackedInt,setter=mySetUnbackedInt:) int unbackedInt; 26 @property int backedInt; 27 @property (nonatomic, assign) id <MyProtocol> idWithProtocol; 28 @end 29 30 @implementation BaseClass 31 @synthesize unbackedInt; 32 @synthesize backedInt = _backedInt; 33 34 + (BaseClass *) baseClassWithBackedInt: (int) inInt andUnbackedInt: (int) inOtherInt 35 { 36 BaseClass *new = [[BaseClass alloc] init]; 37 38 new->_backedInt = inInt; 39 new->unbackedInt = inOtherInt; 40 41 return new; 42 } 43 44 - (int) myGetUnbackedInt 45 { 46 // NSLog (@"Getting BaseClass::unbackedInt - %d.\n", unbackedInt); 47 _access_count++; 48 return unbackedInt; 49 } 50 51 - (void) mySetUnbackedInt: (int) in_int 52 { 53 // NSLog (@"Setting BaseClass::unbackedInt from %d to %d.", unbackedInt, in_int); 54 _access_count++; 55 unbackedInt = in_int; 56 } 57 58 - (int) nonexistantInt 59 { 60 // NSLog (@"Getting BaseClass::nonexistantInt - %d.\n", 5); 61 _access_count++; 62 return 6; 63 } 64 65 - (void) setNonexistantInt: (int) in_int 66 { 67 // NSLog (@"Setting BaseClass::nonexistantInt from 7 to %d.", in_int); 68 _access_count++; 69 } 70 71 - (int) getAccessCount 72 { 73 return _access_count; 74 } 75 @end 76 77 int 78 main () 79 { 80 BaseClass *mine = [BaseClass baseClassWithBackedInt: 10 andUnbackedInt: 20]; 81 82 // Set a breakpoint here. 83 int nonexistant = mine.nonexistantInt; 84 85 int backedInt = mine.backedInt; 86 87 int unbackedInt = mine.unbackedInt; 88 89 id idWithProtocol = mine.idWithProtocol; 90 91 NSLog (@"Results for %p: nonexistant: %d backed: %d unbacked: %d accessCount: %d.", 92 mine, 93 nonexistant, 94 backedInt, 95 unbackedInt, 96 [mine getAccessCount]); 97 return 0; 98 99 } 100 101