0

I'm trying to combine strings with numbers to load dynamic a texture. I found out that the behavior is different if I use a NSString and assign a static string or I combine the string with a number.

// version 1
NSString* textureName;
textureName = @"texture_1";

// version 2
NSString* textureName;
textureName = [NSString stringWithFormat:@"texture_%i ",index];

When I try to get an item from my dictionary with textureName as my key I get the item with the first version of my code but I dont get it with the second version.

The debugger shows in version 1 the type "_NSCFConstantString" and in version 2 the type "_NSCFString".

How can I get an item out of my dictionary with a dynamic string?

2
  • 1
    Can you include the code where you define index and where you try to retrieve the value? Commented Dec 26, 2011 at 19:49
  • Please show how you retrieve data from dictionary. Also, what is index, where, how is it declared? Commented Dec 26, 2011 at 19:49

2 Answers 2

3

The problem is that your second string has a space at the end. @"texture_1" is not considered the same as @"texture_1 ".

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, obviously I was blind... :-) I thought I am going crazy.
2

This maybe as simple as overlooking a trailing whitespace

Look at the last character in version 2. There is space on the end. Remove it and it should work.

// version 2
NSString* textureName;
textureName = [NSString stringWithFormat:@"texture_%i ",index];

1 Comment

Thank you, obviously I was blind... :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.