Skip to content

Instantly share code, notes, and snippets.

@b9AobJ
Forked from Koze/OSTypeFourCharCodeToNSString.m
Created November 10, 2016 06:08
Show Gist options
  • Save b9AobJ/a4521df275bb5479569b9c4fd59d4ecb to your computer and use it in GitHub Desktop.
Save b9AobJ/a4521df275bb5479569b9c4fd59d4ecb 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