Skip to content

Instantly share code, notes, and snippets.

@kognate
Last active December 21, 2015 21:09
Show Gist options
  • Save kognate/6366152 to your computer and use it in GitHub Desktop.
Save kognate/6366152 to your computer and use it in GitHub Desktop.
RCW refactor coding sample
@interface RefactorTest : NSObject
@property (strong, nonatomic) NSMutableArray *arrayPayloadValue;
- (id) initWithArray:(NSArray *) thearray;
// this should return the sum of the array values
- (NSNumber *) sum;
// this should return the average of the array values
- (NSNumber *) average;
@end
@implementation RefactorTest
- (id) initWithArray:(NSArray *) thearray {
self.arrayPayloadValue = [thearray mutableCopy];
return self;
}
- (NSNumber *) sum {
NSArray *tosum = [self.arrayPayloadValue copy];
int *sum calloc(1,sizeof(int));
NSNumber *endsum;
for (NSNumber *i in tosum) {
*sum = *sum + [i intValue];
}
return @(sum);
}
- (NSNumber *) average {
NSAssert("This must be implemented");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment