I have three NSString properties declared like this:
@property(nonatomic,retain) NSString *currentPassword;
@property(nonatomic,retain) NSString *newPassword;
@property(nonatomic,retain) NSString *confirmPassword;
I initialize them in a viewDidLoad method:
currentPassword = [[NSString alloc]init];
newPassword = [[NSString alloc]init];
confirmPassword = [[NSString alloc]init];
The funny thing is that they are the same object after initialize them as different objects!

Is this some kind of compiler optimization?
Thank you
As NSString objects are immutable (i.e. cannot be changed after they are created) and there’s no sense in creating several different instances of the same immutable strings, system tries to reuse existing objects whenever possible.
Using constructor with no parameters may be one of examples. You can also check that
+stringWithString:(and-initWithString:) also return the (retained) parameter string, andcopymethod inNSStringis equivalent toretain.Remember that optimization is only possible because we know NSString instance is not going to change and the same tests with
NSMutableStringmost likely will to create new string instances.P.S. About NSAssert usage:
So your assert condition should be reversed: