[NSString stringWithFormat:@"%@/%@/%@", one, two, three];
I'm guessing you're not happy with multiple appends (a+b+c+d), in which case you could do:
NSLog(@"%@", [Util append:one, @" ", two, nil]); // "one two"
NSLog(@"%@", [Util append:three, @"/", two, @"/", one, nil]); // three/two/one
using something like
+ (NSString *) append:(id) first, ...
NSString * result = @"";
result = [result stringByAppendingString:first];
while (eachArg = va_arg(alist, id))
result = [result stringByAppendingString:eachArg];
You should create a header file like
FOUNDATION_EXPORT NSString *const MyFirstConstant;
FOUNDATION_EXPORT NSString *const MySecondConstant;
(you can use
extern instead of
FOUNDATION_EXPORT if your code will not be used in mixed C/C++ environments or on other platforms)
You can include this file in each file that uses the constants or in the pre-compiled header for the project.
You define these constants in a .m file like
NSString *const MyFirstConstant = @"FirstConstant";
NSString *const MySecondConstant = @"SecondConstant";
Constants.m should be added to your application/framework's target so that it is linked in to the final product.
The advantage of using string constants instead of
#define'd constants is that you can test for equality using pointer comparison (
stringInstance == MyFirstConstant) which is much faster than string comparison (
[stringInstance isEqualToString:MyFirstConstant]) (and easier to read, IMO).
From NSDate class reference: