2 Replies
      Latest reply on Apr 5, 2019 2:23 AM by eskimo
      fpiraneo Level 1 Level 1 (0 points)

        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 : Set = [URLResourceKey.nameKey, URLResourceKey.creationDateKey, URLResourceKey.contentModificationDateKey, URLResourceKey.fileSizeKey, URLResourceKey.isPackageKey, URLResourceKey.thumbnailKey, URLResourceKey.customIconKey]
           do {
               let properties = try localURL.resourceValues(forKeys: requiredAttributes)
        metadata.name = properties[URLResourceKey.nameKey] as? String ?? ""


            let customIcon = properties[URLResourceKey.customIconKey] as? NSImage ?? nil
               if customIcon != nil {
        let saveURL = URL(fileURLWithPath: "/Users/fpiraneo/Desktop/fileicon.png")
        try customIcon!.savePNGRepresentationToURL(url: saveURL)


        let customThumbnail = properties[URLResourceKey.thumbnailKey] as? NSImage ?? nil
        if customThumbnail != nil {
        let saveURL = URL(fileURLWithPath: "/Users/fpiraneo/Desktop/filethumbnail.png")
          try customThumbnail!.savePNGRepresentationToURL(url: saveURL)
           } catch {
               let errorDescription = "Error reading file attributes: \(localURL.absoluteString)"


        Thank you for your help.