Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends ,


NSString str1=@"1st string";
NSstring str2=@"2nd String";
str2=[NSString stringWithString:str1]; // str2 is immutable , although the
// content of str2 changed after this
// statement to str1 .




After reading the above code, please tell me if str2 object is immutable then why
the content of the str2 got changed ?
Posted

1 solution

Because the string is immutable, but not the reference. You assigned a new, immutable string to str2 in the third line witrhout changing the content of the original string.
 
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