Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Created May 17, 2013 21:29
Show Gist options
  • Save jameswomack/5602102 to your computer and use it in GitHub Desktop.
Save jameswomack/5602102 to your computer and use it in GitHub Desktop.
Four-char UInt32 type codes to NSString and back
NSString *ABTypeCodeToString(UInt32 typeCode)
{
char string[5] = {*(((char*)&typeCode)+3), *(((char*)&typeCode)+2), *(((char*)&typeCode)+1), *(((char*)&typeCode)+0),0};
NSString *codeWithDot = @(string);
return [codeWithDot stringByTrimmingCharactersInSet:NSCharacterSet.punctuationCharacterSet];
}
UInt32 ABStringToTypeCode(NSString *typeString)
{
const char *s = typeString.UTF8String;
UInt32 typeCode = s[3] | (s[2] << 8) | (s[1] << 16) | (s[0] << 24);
return typeCode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment