Last active
December 12, 2015 07:09
-
-
Save woolsweater/4734460 to your computer and use it in GitHub Desktop.
Private ivar that is accessible in subclasses.
This file contains hidden or 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 "Monongahela.h" | |
| @interface FortHill : Monongahela | |
| @end |
This file contains hidden or 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 "FortHill.h" | |
| #import "Monongahela_Private.h" | |
| // Only override getter; use superclass's setter | |
| - (CGPoint)frog | |
| { | |
| return CGPointMake(frog.x + 2.0, frog.y + 5.5); | |
| } | |
| // Override both setter and getter | |
| - (NSData *)crow | |
| { | |
| NSLog(@"This is my crow."); | |
| return crow; // This is the ivar declared in the class extension | |
| } | |
| - (void)setCrow:(NSData *)newCrow | |
| { | |
| NSLog(@"What a lovely new crow!"); | |
| crow = [newCrow copy]; | |
| } | |
| @end |
This file contains hidden or 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 <Foundation/Foundation.h> | |
| @interface Monongahela : NSObject | |
| { | |
| CGPoint frog; | |
| } | |
| @property (assign, nonatomic) CGPoint frog; | |
| @property (copy, nonatomic) NSData * crow; | |
| @property (strong, nonatomic) NSPipe * aardvark; | |
| @end |
This file contains hidden or 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 "Monongahela.h" | |
| #import "Monongahela_Private.h" | |
| @implementation Monongahela | |
| @synthesize frog; // Use existing ivar from public header; create getter and setter | |
| @synthesize crow; // Use existing ivar from extension; create getter and setter | |
| @synthesize aardvark; // Create ivar; use getter and setter below | |
| - (NSPipe *)aardvark | |
| { | |
| NSLog(@"Here's your aardvark!"); | |
| return aardvark; | |
| } | |
| - (void)setAardvark:(NSPipe *)newAardvark | |
| { | |
| NSLog(@"Saving a new aardvark."); | |
| aardvark = newAardvark; | |
| } | |
| @end |
This file contains hidden or 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 "Monongahela.h" | |
| @interface Monongahela () | |
| { | |
| @protected // Ivars in class extensions are @private by default | |
| NSData * crow; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment