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")
}
}
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.