Article:
 |
|
Strings in Cocoa: Part I
|
| Subject: |
|
Comparing @"..." type NSStrings |
| Date: |
|
2001-07-06 15:30:29 |
| From: |
|
halliday
|
|
|
|
Incidentally, due to the uniqueness properties imposed by NSString upon NSString constants (@"..." type NSStrings), the example code:
NSString *string1 = @"A String";
NSString *string2 = @"A String";
BOOL result = string1 == string2;
evaluates to "yes" rather than "no". The compiler recognizes the second NSString to be the same as one it has already seen and simply reuses it. Since these NSStrings are immutable, there is no danger in doing so.
In fact, there are aspects of Cocoa that strongly rely upon this behavior.
|
Showing messages 1 through 3 of 3.
-
Comparing @"..." type NSStrings
2001-07-06 17:02:13
Michael Beam |
[View]
-
Comparing @"..." type NSStrings
2001-07-07 01:18:41
halliday
[View]
-
Comparing @"..." type NSStrings
2001-07-07 00:47:41
halliday
[View]
Mike