this is a more theoretical question than pratical;
Assuming that i have two Strings, one normal and one mutable, if i do:
NSMutableString *prova = [[NSMutableString alloc] init];
NSString *prova2 = [[NSString alloc] init];
[prova appendFormat:@"%@",@"CIAO"];
prova2 = prova;
NSLog(@"String: %@",prova);
NSLog(@"String2: %@",prova2);
[prova setString:@""];
NSLog(@"-String: %@",prova);
NSLog(@"-String2: %@",prova2);
Then the result is:
2013-04-22 22:01:53.604 CodeTest[6974:303] String: CIAO
2013-04-22 22:01:53.605 CodeTest[6974:303] String2: CIAO
2013-04-22 22:01:53.605 CodeTest[6974:303] -String:
2013-04-22 22:01:53.606 CodeTest[6974:303] -String2:
Why does it behave like this?
I just wanna find it out, because i've never encountered such thing before while programming in python, php or C++ (I think i was never confronted with so many different data types as in Obj-c :P )
Thanks
Just in case anyone wants to know how to get over it here is the right code i used to assign the value to the string without losing it after the "blanking" (sostitute to prova2 = prova):
prova2 = [NSString stringWithString:prova];