Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deprecating +sharedMathEvaluator.

The name is wrong.  +shared* implies a singleton, which this is not.  The proper name is +defaultMathEvaluator (like +[NSFileManager defaultManager])
  • Loading branch information...
commit eb77e597227952eca43b5535bac5337f443b7a97 1 parent 06e1b80
@davedelong davedelong authored
View
2  Command line demo/main.m
@@ -21,7 +21,7 @@
void listFunctions() {
printf("\nFunctions available:\n");
- NSArray * functions = [[DDMathEvaluator sharedMathEvaluator] registeredFunctions];
+ NSArray * functions = [[DDMathEvaluator defaultMathEvaluator] registeredFunctions];
for (NSString * function in functions) {
printf("\t%s()\n", [function UTF8String]);
}
View
2  DDMathParser/DDExpression.m
@@ -48,7 +48,7 @@ - (NSNumber *)evaluateWithSubstitutions:(NSDictionary *)substitutions evaluator:
}
- (DDExpression *)simplifiedExpression {
NSError *error = nil;
- DDExpression *simplified = [self simplifiedExpressionWithEvaluator:[DDMathEvaluator sharedMathEvaluator] error:&error];
+ DDExpression *simplified = [self simplifiedExpressionWithEvaluator:[DDMathEvaluator defaultMathEvaluator] error:&error];
if (error != nil) {
NSLog(@"error: %@", error);
return nil;
View
3  DDMathParser/DDMathEvaluator.h
@@ -24,7 +24,8 @@ typedef NSNumber* (^DDVariableResolver)(NSString *);
@property (nonatomic, copy) DDFunctionResolver functionResolver;
@property (nonatomic, copy) DDVariableResolver variableResolver;
-+ (id)sharedMathEvaluator;
++ (id)sharedMathEvaluator __attribute__((deprecated("Use +defaultMathEvaluator instead")));
++ (instancetype)defaultMathEvaluator;
- (BOOL)registerFunction:(DDMathFunction)function forName:(NSString *)functionName;
- (void)unregisterFunctionWithName:(NSString *)functionName;
View
16 DDMathParser/DDMathEvaluator.m
@@ -23,14 +23,18 @@ @implementation DDMathEvaluator {
_DDFunctionEvaluator *_functionEvaluator;
}
-static DDMathEvaluator * _sharedEvaluator = nil;
+ (id)sharedMathEvaluator {
+ return [self defaultMathEvaluator];
+}
+
++ (instancetype)defaultMathEvaluator {
+ static DDMathEvaluator * _defaultEvaluator = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- _sharedEvaluator = [[DDMathEvaluator alloc] init];
+ _defaultEvaluator = [[DDMathEvaluator alloc] init];
});
- return _sharedEvaluator;
+ return _defaultEvaluator;
}
- (id)init {
@@ -49,12 +53,6 @@ - (id)init {
return self;
}
-- (void)dealloc {
- if (self == _sharedEvaluator) {
- _sharedEvaluator = nil;
- }
-}
-
#pragma mark - Properties
- (void)setUsesHighPrecisionEvaluation:(BOOL)usesHighPrecisionEvaluation {
View
2  DDMathParser/NSString+DDMathParsing.m
@@ -27,7 +27,7 @@ - (NSNumber *)numberByEvaluatingStringWithSubstitutions:(NSDictionary *)substitu
- (NSNumber *)numberByEvaluatingStringWithSubstitutions:(NSDictionary *)substitutions error:(NSError **)error {
DDExpression * e = [DDExpression expressionFromString:self error:error];
- return [[DDMathEvaluator sharedMathEvaluator] evaluateExpression:e withSubstitutions:substitutions error:error];
+ return [[DDMathEvaluator defaultMathEvaluator] evaluateExpression:e withSubstitutions:substitutions error:error];
}
@end
View
2  DDMathParser/_DDFunctionExpression.m
@@ -74,7 +74,7 @@ - (DDExpression *)simplifiedExpressionWithEvaluator:(DDMathEvaluator *)evaluator
}
if (canSimplify) {
- if (evaluator == nil) { evaluator = [DDMathEvaluator sharedMathEvaluator]; }
+ if (evaluator == nil) { evaluator = [DDMathEvaluator defaultMathEvaluator]; }
id result = [evaluator evaluateExpression:self withSubstitutions:nil error:error];
Please sign in to comment.
Something went wrong with that request. Please try again.