I’m trying to modify the metadata contained in a JPEG image. It can be any of the metadata in the image, in my example I’m attempting to change to DateTimeDigitized
I’m answering this myself since I found out why it wasn’t saving the data and it looks like this question can help others.
My code is correct, the only issue is that I wasn’t formatting the date properly. Since the date wasn’t in the correct format it was getting pruned by the frameworks. I formatted the date like this and it saved and displayed properly:
let formatter = DateFormatter()
formatter.dateFormat = "yyyy:MM:dd HH:mm:ss"
exif[ImagePropertyExifDateTimeDigitized] = formatter.string(from: Date())
This was in place of the line:
exif[ImagePropertyExifDateTimeDigitized] = Date() as CFDate
The output is now (again pruned to only the relevant properties):
unmodified properties
{
"{Exif}" = {
DateTimeDigitized = "2007:07:31 17:42:01";
DateTimeOriginal = "2007:07:31 17:42:01";
};
}
modified properties
{
"{Exif}" = {
DateTimeDigitized = "2017:05:12 01:04:14";
DateTimeOriginal = "2007:07:31 17:42:01";
};
}
saved properties
{
"{Exif}" = {
DateTimeDigitized = "2017:05:12 01:04:14";
DateTimeOriginal = "2007:07:31 17:42:01";
};
}