Reply to comment

strict warning: Only variables should be passed by reference in /var/www/www.waterworld.com.hk/sites/all/modules/captcha/captcha.inc on line 61.

NSExpression example

NSExpression is a very powerful class in iOS/OSX that calculate formula. We can also pass arguments or parameters to the formula:

NSExpression *expression1 = [NSExpression expressionWithFormat: @"1+2"];
NSLog(@"expression1 %@", [expression1 expressionValueWithObject:nil context:nil]);
NSExpression *expression2 = [NSExpression expressionWithFormat: @"1+%@-%@" argumentArray:@[@1.2, @2.2]];
NSLog(@"expression2 %@", [expression2 expressionValueWithObject:nil context:nil]);
NSMutableDictionary *context = [NSMutableDictionary dictionaryWithDictionary:
@{
@"offset": @1.3
}];
NSExpression *expression3 = [NSExpression expressionWithFormat: @"1+$offset*$offset+2.5"];
NSLog(@"expression3 %@", [expression3 expressionValueWithObject:nil context:context]);

The result will be:

expression1 3
expression2 0
expression3 5.19

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
10 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.