Created
March 25, 2012 05:55
-
-
Save rudyjahchan/2191625 to your computer and use it in GitHub Desktop.
Monkey-Patching iOS with Objective-C Categories Part II: Adding Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyClassWithFakePrivateProperties.h" | |
@interface MyClassWithFakePrivateProperties () | |
@property (nonatomic, strong) NSString *foo; | |
@end | |
@implementation MyClassWithFakePrivateProperties | |
@synthesize foo; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIViewController (TourGuide) | |
@property (nonatomic, retain) NSArray* tourSteps; | |
- (void) displayTour; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIViewController_TourGuide.h" | |
static char tourStepsKey; | |
@implementation UIViewController (TourGuide) | |
- (void) setTourSteps:(NSArray*)tourSteps { | |
objc_setAssociatedObject(self, &tourStepsKey, | |
tourSteps, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
- (NSArray*) getTourSteps { | |
return objc_getAssociatedObject(self, &tourStepsKey); | |
} | |
- (void) displayTour { | |
// run the tour | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIViewController_TourGuide.h" | |
@implementation UIViewController (TourGuide) | |
@synthesize tourSteps = tourSteps_ | |
- (void) displayTour { | |
// run the tour | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIViewController (TourGuide) { | |
@private | |
NSArray* _tourSteps; | |
} | |
@property (nonatomic, retain) NSArray* tourSteps; | |
- (void) displayTour; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment