Created
May 17, 2013 21:29
-
-
Save jameswomack/5602102 to your computer and use it in GitHub Desktop.
Four-char UInt32 type codes to NSString and back
This file contains hidden or 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
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