Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thisma

macrumors member
Original poster
Sep 9, 2008
39
5
I want to put two strings together to form the name of the file passed to a UIImage. I think something like this:

Code:
	NSMutableString *tempName = [NSMutableString stringWithString:@"foo"];
	[tempStemName appendString:@"bar.png"];
	imageOfStem = [UIImage imageNamed:tempName];

will work.

My question is: Is there some way of doing this more simply or without so much juggling; this solution seems very bloated.

I know I can't do this:

Code:
	imageOfStem = [UIImage imageNamed:@"foo" + @"bar.png"];

But, something like:

Code:
	imageOfStem = [UIImage imageNamed:[@"foo" returnStringWithStringAppended:@"bar.png"];

would be good.

trick here is @"foo" needs to remain @"foo"

Sorry to be such a n00b; I'm working on it. I did spend the prerequisite time Googling and found my self more confused afterward.

Please help,
-thisma
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
This will work:

Code:
imageOfStem = [UIImage imageNamed:[@"foo" stringByAppendingString:@"bar.png"]];
imageOfStem = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@" @"foo", @"bar.png"]];

Working with immutable strings sometimes seems odd vs other languages that have a string concatenation operator.
 

thisma

macrumors member
Original poster
Sep 9, 2008
39
5
This will work:

Code:
imageOfStem = [UIImage imageNamed:[@"foo" stringByAppendingString:@"bar.png"]];
imageOfStem = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@" @"foo", @"bar.png"]];

Awesome :D thank you. That's what I was looking for.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.