开发者

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

开发者 https://www.devze.com 2023-01-19 06:08 出处:网络
I am writing an application that makes use of Uniform Type Identifiers. Specifically, I am calling UTTypeCreateAllIdentifiersForTag() and passing it various MIME types.

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 define开发者_如何学Cd 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消