Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created May 16, 2016 19:39
Show Gist options
  • Save robertmryan/6c59c1fc44887b270c38758c6960dcae to your computer and use it in GitHub Desktop.
Save robertmryan/6c59c1fc44887b270c38758c6960dcae to your computer and use it in GitHub Desktop.
@interface Triangle : NSObject
@property (nonatomic) double sideALength;
@property (nonatomic) double sideBLength;
@property (nonatomic) double height;
@property (nonatomic, readonly) double area;
@end
@implementation Triangle
- (double)area {
// do your calculation here
return calculatedValue;
}
@end
@robertmryan
Copy link
Author

Note, there is no asterisk next to the double properties, as double is a fundamental data type, not an object. But if you then use the Triangle class, that instance is an object, so you'd use an asterisk there, e.g.:

Triangle *foo = [[Triangle alloc] init];
foo.sideALength = 5.0;
foo.sideBLength = 4.0;
foo.height = 3.0;

double result = foo.area;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment