I’m working through the Stanford iPhone podcasts and have some basic questions.
The first: why is there no easy string concatenation? (or am I just missing it?)
I needed help with the NSLog below, and have no idea what it’s currently doing (the %@ part). Do you just substitute those in wherever you need concatenation, and then comma separate the values at the end?
NSString *path = @"~";
NSString *absolutePath = [path stringByExpandingTildeInPath];
NSLog(@"My home folder is at '%@'", absolutePath);
whereas with any other programing language I’d have done it like this:
NSLog(@"My home folder is at " + absolutePath);
Thanks! (Additionally, any good guides/references for someone familiar with Java/C#/etc style syntax transitioning to Objective-C?)
%@is a placeholder in a format string, for a NSString instance.When you do something like:
You are telling NSLog to replace the
%@placeholder with the string called absolutePath.Likewise, if you put more placeholders, you can specify more values to replace those placeholders like this:
Will print:
An easy way to do string concatenation:
You can’t have a
+sign as a string concatenate operator, since there is no operator overloading in Objective-C.Hope it helps.