I'm trying to read the URLResourceKey.customIconKey
and URLResourceKey.thumbnailKey
file attributes with a Swift 4 app; as you guess I have some issue because no NSImage
will be returned.
Questions: Does the two above keys refers to the custom icon (i.e. the Adobe Acrobat documents icon) and the thumbnails of the png / jpeg files?
If it's not the case, what the two keys really refers to?
Apple documentation has a really short description and google gave no results about.
By the way, here is the code I'm working on.
// Get file informations
let requiredAttributes = [URLResourceKey.nameKey, URLResourceKey.creationDateKey, URLResourceKey.contentModificationDateKey, URLResourceKey.fileSizeKey, URLResourceKey.isPackageKey, URLResourceKey.thumbnailKey, URLResourceKey.customIconKey]
do {
let properties = try (localURL as NSURL).resourceValues(forKeys: requiredAttributes)
...
let customIcon = properties[URLResourceKey.customIconKey] as? NSImage ?? nil
if customIcon != nil {
let saveURL = URL(fileURLWithPath: "/Users/foo/Desktop/fileicon.png")
try customIcon!.savePNGRepresentationToURL(url: saveURL)
}
let customThumbnail = properties[URLResourceKey.thumbnailKey] as? NSImage ?? nil
if customThumbnail != nil {
let saveURL = URL(fileURLWithPath: "/Users/foo/Desktop/filethumbnail.png")
try customThumbnail!.savePNGRepresentationToURL(url: saveURL)
}
} catch {...}
When inspecting properties
dictionary the two customIconKey
and thumbnailKey
are not set.
Thank you for your help.