Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active November 10, 2016 06:08
Show Gist options
  • Save Koze/489f5ae95d68d280ffe8 to your computer and use it in GitHub Desktop.
Save Koze/489f5ae95d68d280ffe8 to your computer and use it in GitHub Desktop.
OSType, FourCharCode to NSString
// XX is own prefix
NSString *XXStringForOSType(OSType type) {
unichar c[4];
c[0] = (type >> 24) & 0xFF;
c[1] = (type >> 16) & 0xFF;
c[2] = (type >> 8) & 0xFF;
c[3] = (type >> 0) & 0xFF;
NSString *string = [NSString stringWithCharacters:c length:4];
return string;
}
- (void)test
{
OSType type = 'appl';
#if !TARGET_OS_IOS
NSLog(@"type = %@", NSFileTypeForHFSTypeCode(type));
// type = 'appl'
NSLog(@"type = %@", CFBridgingRelease(UTCreateStringForOSType(type)));
// type = appl
#endif
NSLog(@"type = %@", XXStringForOSType(type));
// type = appl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment