Skip to content

Instantly share code, notes, and snippets.

@n-b
Created January 19, 2013 00:25
Show Gist options
  • Save n-b/4569846 to your computer and use it in GitHub Desktop.
Save n-b/4569846 to your computer and use it in GitHub Desktop.
//
// 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