Created
January 19, 2013 00:25
-
-
Save n-b/4569846 to your computer and use it in GitHub Desktop.
Test code for http://bou.io/ConstantStringsInObjC.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// clang -framework Foundation NSConstantString_test.m; ./a.out; rm ./a.out | |
// | |
#import <Foundation/Foundation.h> | |
#define PrintObjectInfo(obj) \ | |
do{id _obj = ( obj );\ | |
printf("%-61s %-20s %-16p %ld\n", #obj" :", [NSStringFromClass([_obj class]) UTF8String], _obj, [_obj retainCount]);\ | |
}while(0); | |
int main(int argc, const char * argv[]) | |
{ | |
NSString *a = @"a"; | |
PrintObjectInfo(a); | |
PrintObjectInfo(@"a"); | |
PrintObjectInfo(@"some string"); | |
PrintObjectInfo([@"a" copy]); | |
PrintObjectInfo([@"a" mutableCopy]); | |
PrintObjectInfo([[@"a" mutableCopy] copy]); | |
PrintObjectInfo([[@"b" mutableCopy] copy]); | |
PrintObjectInfo([[@"ab" mutableCopy] copy]); | |
PrintObjectInfo([[@"$" mutableCopy] copy]); | |
PrintObjectInfo([[@"/" mutableCopy] copy]); | |
PrintObjectInfo([[@"€" mutableCopy] copy]); | |
PrintObjectInfo([[@"§" mutableCopy] copy]); | |
PrintObjectInfo([[[@"a" mutableCopy] copy] retain]); | |
PrintObjectInfo(([NSString stringWithFormat:@"%s","a"])); | |
PrintObjectInfo([@"/some/path/to/a" lastPathComponent]); | |
PrintObjectInfo([[@"/some/path/to/a" lastPathComponent] copy]); | |
PrintObjectInfo([[[@"/some/path/to/a" lastPathComponent] mutableCopy] copy]); | |
PrintObjectInfo([[[@"path/a" lastPathComponent] mutableCopy] copy]); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment