I declare an object in the beginning of M file as follows:

NSMutableString *SomeString;

And in a method I try to init it:

SomeString  = [NSMutableString stringWithFormat:@"%c",'0'];
NSMutableString *SomeOtherString = [NSMutableString stringWithFormat:@"%c",'0'];

When I debug after the above line, I see that SomeOtherString holds the string "0" but SomeString remains empty. What am I doing wrong?

有帮助吗?

解决方案

I think that's because stringWithFormat returns an autorelease object while your SomeString is a global variable , so SomeString is out of scope and released.

try this :

  SomeString  = [[NSMutableString alloc] initWithFormat:@"%c",'0'];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top