2

I often create my own document type for my desktop applications. But I have never registered my own custom UTI. Anyway, I want to save a simple Dictionary data as a data (NSData) file like the following.

@IBAction func testClicked(_ sender: NSButton) {
    let savePath = self.documentPath() // setting a default path
    let savePanel = NSSavePanel()
    savePanel.directoryURL = NSURL.fileURL(withPath: savePath)
    savePanel.title = ""
    savePanel.message = ""
    savePanel.nameFieldStringValue = "File"
    savePanel.showsHiddenFiles = false
    savePanel.showsTagField = false
    savePanel.canCreateDirectories = true
    savePanel.allowsOtherFileTypes = false
    savePanel.allowedFileTypes = ["customtype"]
    savePanel.isExtensionHidden = false
    if savePanel.runModal() == NSFileHandlingPanelOKButton {
        let dict = ["title": "New York Nightly News", "url": "http://www.newyorknightlynews.net/cmlink/TopNews.rss"] as Dictionary<String, String>
        let data = NSKeyedArchiver.archivedData(withRootObject: dict)
        do {
            try data.write(to: savePanel.url!, options: .atomic)
        }
        catch {

        }
    } else {
        print("canceled")
    }
}

enter image description here

I have set up a document type and an exported UTI as shown above.

Initially, I set the UTTypeConformsTo type to public.data. But I've changed it to public.xml and public.text. Yet, an exported file has no file icon. It doesn't appear that my custom UTI is correctly recognized. My goal is to let this desktop application produces a file such that the user can send it to an iOS equivalent through AirDrop. What am I doing wrong? Thanks.

3
  • Does it work without the save panel? Commented Jun 18, 2017 at 10:46
  • No, it doesn't. My iOS app does accept a file if I change the file type to xml, though. Commented Jun 18, 2017 at 10:57
  • So the save panel has nothing to do with it? Maybe you should change the title to attract icon/UTI specialists. Commented Jun 18, 2017 at 14:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.