Question

I am writing an application that makes use of Uniform Type Identifiers. Specifically, I am calling UTTypeCreateAllIdentifiersForTag() and passing it various MIME types.

My hope was that this function (as distinct from UTTypeCreatePreferredIdentifierForTag()) would give me the most specific UTI as well as all the UTIs to which it conforms. This appears not to be the case -- it either returns a single UTI, or the secondary UTIs are spurious.

There is the UTTypeConformsTo() function defined in the same header file, but I'd prefer a function that returns an array of all the types to which this UTI conforms.

There appears to be hope for me, as MDItemCopyAttributeList() will return such a list. That said, it requires an MDItemRef, which can be created from either a file path or URL -- which isn't great. Sometimes my data is only stored in-memory and I only have a MIME type to go by.

Do I have to iterate through the entire database of UTIs to get this information or am I missing something?

Was it helpful?

Solution

I was indeed missing something: the very obvious solution. While I was trawling through the symbols exported by LaunchServices (and noticed the interesting, but private UTTypeCopyPedigree()), I was reminded of UTTypeCopyDeclaration(), which is defined.

UTTypeCopyDeclaration() is given a UTI and returns (as a CFDictionaryRef) the property list in which the UTI was defined. The object in this dictionary with key kUTTypeConformsToKey is either a CFArrayRef or CFStringRef. In the case of an array, one can recursively iterate until a base type is reached.

This is how I built up an inheritance tree for a given UTI. I hope this helps anyone else with the same issue.

OTHER TIPS

https://github.com/nst/UTIsExplorer generates a hierarchy graph of UTIs in "dot" format for graphviz.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top