Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSMutableString *str1;
    [str1 setString:@"again"];
    NSLog(@"string is -- %@",str1);   // It prints " string is -- (null) " 
    [str1 release];
    [pool drain];
    return 0;
}

------------------------------------------------------------------------------------
C++
int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSMutableString *str1;
    
    str1 = [NSMutableString stringWithString:@"hello again "]; // By adding this 
   [str1 setString:@"again"];                // Now this statements works properly .
    NSLog(@"string is -- %@",str1);    
    [str1 release];
    [pool drain];
    return 0;
}

I can not understand why if I use setString method first, str1 is not initializing??
Posted
Updated 2-Mar-12 23:30pm
v2
Comments
André Kraak 3-Mar-12 5:31am    
Edited question:
Added pre tags
"Treat my content as plain text..." option disabled.

1 solution

Don't forget init NSMutableString

NSMutableString *str1 = [[NSMutableString alloc]init];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900