I would like to know how to evaluate a string representation of an equation as if it were a real equation:
if(@\"15+14==23\")
{
//True statement...
}
els
NSString *equation = @"15+14==29";
NSPredicate *pred = [NSPredicate predicateWithFormat:equation];
NSExpression *LeftExp = [pred leftExpression];
NSExpression *RightExp = [pred rightExpression];
NSNumber *left = [LeftExp expressionValueWithObject:nil context:nil];
NSNumber *right = [RightExp expressionValueWithObject:nil context:nil];
if ([left isEqualToNumber:right]) {
NSLog(@"yes left is equal to right");
}
else{
NSLog(@"yes left is NOT equal to right");
}
NSLog(@"left %@", left);
NSLog(@"right %@", right);