SpaceDog SpaceDog - 1 year ago 90
iOS Question

Getting the file kind by extension on iOS

When I take a

file and do
File, Info
on OSX's finder I see

Kind: Digital Asset Exchange (DAE)


Kind: Rich Text Document with Attachments

But this is OSX. Now, how do I discover the kind of file on iOS by the NSURL of that file?

Rob Rob
Answer Source

There may be other ways, but one way is to use the uniform type identifier (UTI) services provided by MobileCoreServices.

import MobileCoreServices

Just get the description associated with the extension's UTI:

if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, nil)?.takeRetainedValue(), let description = UTTypeCopyDescription(uti)?.takeRetainedValue() {

See the How the System Identifies the Type of Content in a File in the File System Programming Guide.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download