views:

69

answers:

2

Hello All:

I have two files(file1.m and file2.m) and two strings(NSString *str1 = [[NSString alloc] initWithString:@"hello!"] in file1.m and NSString *str2 in file2.m).I set str2 = str1 by a method and then the str2's value is "hello!".

Then I change the str2 to "hello hello!" in file2.m,and i want the str1 in file1.m is also changed to "hello hello!".

How to do? If you konw,please tell me.

Thank you!

+3  A: 

How would you do the same thing in C, or Java, or most any other language? While the syntax differs, the general concepts of using a global variable, a function, or class methods does not.

In short, it appears you need some more study and just providing some code wouldn't do much to help.

Wade Williams
In C,I use char*。I can use NSMutableArray* in different files,but cann't use NSString *。
lqf
If you called a method to set str2 = str1, why wouldn't have to call a method to set str1 = str2? Equals is an assignment operator - it's not bidirectional.
Wade Williams
A: 

properties. when one changes, change the other.

agentfll
Thank you!When I change the str2 to "hello hello!" in file2.m,But the str1 in file1.m isn't changed to "hello hello!".Why?
lqf
use some glue code. make a setter called setStr2:(NSString *)newValue and in it set str1.
agentfll
thank you very much!
lqf