Given a UTI (Uniform Type Identifier), find all types to which it conforms
Asked Answered
K

2

7

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?

Kliman answered 11/10, 2010 at 6:37 Comment(0)
K
7

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.

Kliman answered 22/10, 2010 at 0:38 Comment(0)
F
0

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

Fluoro answered 9/2, 2016 at 0:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.