Getting UTI file extension

Asked by At

I'm trying to get the file extension of a dropped file in my app. I have the following basic code in my dropInteraction:performDrop: method:

public func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
    for item in session.items {
        item.itemProvider.loadItem(forTypeIdentifier: "public.filename-extension", options: nil) { (data, error) in
            if let data = data as? String {
                print(data)
            }
        }
    }
}

The completion handler returns data as nil with the following error:

Cannot load representation of type public.filename-extension

Can anyone tell me what I'm doing wrong here? Is iOS unable to work with this identifier for some reason? (The public.data identifier meanwhile does return data)

0 Answers