I have been trying to add a thumbnail image to the icon for a UIDocument
application. The example I have been given is relatively straightforward. Assigning the image to a thumbnailDictionaryKey
by overriding the fileAttributesToWrite
function from the class of UIDocument as shown below.
Note 1: self.thumbnail is an image from my document.
Note 2: I have seen the thumbnailDictionaryKey
with and without the rawValue added at the end. I see no difference when I run it.
override func fileAttributesToWrite(to url: URL, for saveOperation: UIDocument.SaveOperation) throws -> [AnyHashable : Any] {
var attributes = try super.fileAttributesToWrite(to: url, for: saveOperation)
print("in fileAttributes")
if let thumbnail = self.thumbnail {
attributes[URLResourceKey.thumbnailDictionaryKey.rawValue] =
[URLThumbnailDictionaryItem.NSThumbnail1024x1024SizeKey:thumbnail]
}
return attributes
}
The code is compiling but it is not showing the image on the thumbnail as desired. In the iOS file manager it is still the app's icon.
One thing I am noticing is I am not seeing the fileAttributesToWrite
function being executed. (The print line is there to check that.)
Is there a step I am leaving out? Do I need the fileAttributesToWrite
to be forced to run?