mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-28 01:31:23 +00:00
34 lines
751 B
Objective-C
34 lines
751 B
Objective-C
#import <Foundation/Foundation.h>
|
|
@interface Calculator : NSObject
|
|
@property (nonatomic, strong) NSString *name;
|
|
- (void)reset;
|
|
- (NSInteger)add:(NSInteger)a to:(NSInteger)b;
|
|
- (NSInteger)multiply:(NSInteger)a with:(NSInteger)b;
|
|
+ (instancetype)sharedCalculator;
|
|
@end
|
|
|
|
@implementation Calculator
|
|
- (void)reset {
|
|
NSLog(@"reset");
|
|
}
|
|
|
|
- (NSInteger)add:(NSInteger)a to:(NSInteger)b {
|
|
return a + b;
|
|
}
|
|
|
|
- (NSInteger)multiply:(NSInteger)a with:(NSInteger)b {
|
|
return a * b;
|
|
}
|
|
|
|
+ (instancetype)sharedCalculator {
|
|
Calculator *calc = [Calculator alloc];
|
|
return [calc init];
|
|
}
|
|
@end
|
|
|
|
void runCalculatorSample(void) {
|
|
Calculator *calc = [Calculator sharedCalculator];
|
|
[calc reset];
|
|
[calc add:5 to:3];
|
|
[calc multiply:2 with:4];
|
|
}
|