Your example is unsuccessful - if you use the string literal @ "Foo" in two places in the code, the compiler will provide them with the same address (i.e. uses the same static instance of the string). Example:
heimdall: Documents leeg $ cat foostrings.m
#import <Foundation/Foundation.h> int main(int argc, char **argv) { NSString *string1 = @"Foo"; NSString *string2 = @"Foo"; printf("string1: %p\nstring2: %p\n", string1, string2); return 0; }
heimdall: Documents leeg $. / foostrings
string1: 0x100001048
string2: 0x100001048
user23743
source share