Skip to content

Instantly share code, notes, and snippets.

@jparishy
Last active December 14, 2015 02:59
Show Gist options
  • Save jparishy/5018161 to your computer and use it in GitHub Desktop.
Save jparishy/5018161 to your computer and use it in GitHub Desktop.
RACSignal *latest = [RACSignal combineLatest:@[ self.maxWeightTextField.rac_textSignal, self.maxRepsTextField.rac_textSignal ]];
[latest subscribeNext:^(RACTuple *values) {
RACTupleUnpack(NSString *maxWeight, NSString *maxReps) = values;
CGFloat maxWeightValue = maxWeight.floatValue;
NSInteger repIndex = maxReps.integerValue;
CGFloat percentages[12] = {
1.00f,
0.95f,
0.90f,
0.88f,
0.86f,
0.83f,
0.80f,
0.78f,
0.76f,
0.75f,
0.72f,
0.70f
};
repIndex = MAX(1, repIndex);
repIndex = MIN(12, repIndex);
CGFloat percentage = percentages[repIndex - 1];
CGFloat oneRepMax = maxWeightValue / percentage;
self.oneRepMaxTextField.text = [NSString stringWithFormat:@"%.02f", oneRepMax];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment