Evaluate math expression in string? (NSString) [duplicate] - objective-c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is a fast C or Objective-C math parser?
I have a NSString which represents a calculation eg. #"(10+10)*2" and I want to evaluate the string as if it was actually something like this;
double result = (10+10)*2;
What is the most straightforward approach to take in iOS?

Take a look at Dave DeLong's DDMathParser framework.

You can use GCMathParser.

Related

Objective C syntax, iOS sample code [duplicate]

This question already has answers here:
What does a type name in parentheses before a variable mean?
(3 answers)
Closed 8 years ago.
I'm learning objective-C and I was looking at some sample code from:
https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Listings/SamplePhotosApp_AAPLAssetGridViewController_m.html#//apple_ref/doc/uid/TP40014575-SamplePhotosApp_AAPLAssetGridViewController_m-DontLinkElementID_8
I'm confused about this line of code here:
CGSize cellSize = ((UICollectionViewFlowLayout *)self.collectionViewLayout).itemSize;
I understand that it's trying to get the itemSize property and store it into cellSize, but I have no idea what ((UICollectionViewFlowLayout *)self.collectionViewLayout) is all about. Can someone break it down for me? Is there another way to write this line of code?
What it means is:
Cast self.collectionViewLayout to be of UICollectionViewFlowLayout type. Then of self.collectionViewLayout get the itemSize property. Finally, save everything is a property of type CGSize.
I believe is a elegant and concise way of writing it.

Creating a Map<Object,Array<Object>> in objective c [duplicate]

This question already has answers here:
What is the Java equivalent of Objective-C's NSDictionary?
(3 answers)
Closed 9 years ago.
I am interested in creating the java equivalent of a Map data structure that looks as follows:
Map <Object ---> NSMutableArray of objects>
or
Map<Object,Array<Object>>
Can anyone provide guidance on what would be the best way of doing this in objective c as I am fairly new to the language.
Objective-c does not have typed collections. You just create NSMutableDictionary instance, and put NSMutableArray into the values.

Combining two strings for a label's text [duplicate]

This question already has answers here:
Setting a cell's text with multiple JSON objects
(3 answers)
Closed 9 years ago.
Real beginners question here. I'm doing some tutorials and I'm expanding on them with scenarios that might come in to play.
Anyhow, I know that the following works:
lblCopyStatus.text = #"Test";
But how would do:
lblCopyStatus.text = #"Test" & lbltest.text;
e.g. get the text from another label into the text. I hope that makes sense :)
For example:
lblCopyStatus.text = [NSString stringWithFormat:#"Test %#", lbltest.text];

iOS - how do I check if a string is numeric or not? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iPhone how to check that a string is numeric only
I am trying to look up some basic functionality in Objective C, but can't seem to locate the basic answer.
What I really need is to check
if ( some_string is numeric )
{
}
I would assume there would just be some built in function for that. No?
I am looking at this StackOverflow question How to check if NSString is numeric or not and they seem to be doing things the very complicated way.
Isn't there some basic check I can do in one simple line?
Thanks!
Isn't there some basic check I can do in one simple line?
No.
NSScanner *scanner = [NSScanner scannerWithString:testString];
BOOL isNumeric = [scanner scanInteger:NULL] && [scanner isAtEnd];
If you want to allow decimal digits exchange scanInteger: by scanDouble:.

What does the output of NSLog exactly mean? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
NSLog 10b meaning?
I am new to objc and iOS development. And, I have a question about NSLog. As we know, NSLog will log message like this:
2011-07-16 23:19:35.467 HelloWorld[11166:7c37] say hello to iOS.
Obviously the format is date time ProjectName, but what does the [11166:7c37] part mean?
Its a process / thread ID I believe.