Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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
You can’t perform that action at this time.