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?)
%@
is a placeholder in a format string, for a NSString instance.
When you do something like:
NSLog(@"My home folder is at '%@'", absolutePath);
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:
NSString *absolutePath = @"/home/whatever";
NSLog(@"My home #%d folder is at '%@'", 5, absolutePath);
Will print:
My home #5 is at /home/whatever
An easy way to do string concatenation:
NSString *s1 = @"Hello, ";
NSString *s2 = @"world.";
NSString *s = [NSString stringWithFormat:@"%@%@", s1, s2];
// s will be "Hello, world."
You can't have a +
sign as a string concatenate operator, since there is no operator overloading in Objective-C.
Hope it helps.