Search code examples
xcodemacoscocoauti

In cocoa, how do I save text with a particular UTI


I would like to export some data as a certain UTI type (e.g. public.text). If I save the text file, I can see with mdls that the UTI type is public.data - but I can't find anywhere find any API's to choose with UTI the file is.

It seems to work if I add an extension '.txt' but I don't want that. In fact, I need to set the file to have certain UTI so another program can load it.


Solution

  • I don't think that you can export something with a public.text UTI. An UTI sort of represents a kind of file abstractly. That is, with this particular UTI you can reference all kind of text files, regardless of their extension (.txt, .text, .md, .html etc.). I think that the .txt extension is the best one to represent a general text file.

    If the other program you mention is able to open files with the public.text UTI, then it will also accept .txt (and all those other extensions).

    You can read Apple's Introduction to Uniform Type Identifiers for more info about UTIs.