Skip to content

Instantly share code, notes, and snippets.

@leiless
Created February 26, 2019 02:17
Show Gist options
  • Save leiless/884840ccd4c93450987a45f22edcf38b to your computer and use it in GitHub Desktop.
Save leiless/884840ccd4c93450987a45f22edcf38b to your computer and use it in GitHub Desktop.
/**
* Creates an array of all uniform type identifiers indicated
* by the specified tag under builtin tag classes
* @inTag: the tag string
* @inConformingToUTI the identifier of a type to which the result must conform
* @return a new CFArrayRef containing all type identifiers
* NULL if no inConformingToUTI match or memory failure
* Ownership follows the The Create Rule
*/
CFArrayRef UTTypeCreateBuiltinIdentifiersForTag(
__nonnull CFStringRef inTag,
__nullable CFStringRef inConformingToUTI)
{
static CFStringRef tags[4];
CFMutableArrayRef arr;
CFStringRef iden;
size_t i;
tags[0] = kUTTagClassFilenameExtension;
tags[1] = kUTTagClassOSType;
tags[2] = kUTTagClassMIMEType;
tags[3] = kUTTagClassNSPboardType;
arr = CFArrayCreateMutable(kCFAllocatorDefault, ARRAY_SIZE(tags), &kCFTypeArrayCallBacks);
if (arr != NULL) {
for (i = 0; i < ARRAY_SIZE(tags); i++) {
iden = UTTypeCreatePreferredIdentifierForTag(tags[i], inTag, inConformingToUTI);
if (iden != NULL) CFArrayAppendValue(arr, iden);
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment