Possible Duplicate:
NSString immutable allows to change its values?
I want to point to an object where in, if I make changes to one object. the same change has to reflect to other object. How to do that?
I have done a sample, but it is not working.
Please check the code once. What is the mistake in my code?
-(void)viewDidLoad{
str = [[NSString alloc] initWithString:@"Taruni"];
str2=str;
str2=@"Kalpana chawla";
[self changeStr:str];
NSLog(@"str = %@",str);
[str release];
[str release];
[super viewDidLoad];
}
-(void)changeStr:(NSString *)x
{
x=@"Chandra";
}
In .h file, I have declared in this way
@property(nonatomic,assign) NSString *str;
@property(nonatomic,assign) NSString *str2;
If I change the value of str2, str is not getting reflected.
How to do that?
Try below code,