Search code examples
swiftcocoametadataexifnsimage

How to get the date from a NSImage


I'm working on a Mac App. I am relatively new to cocoa development and I'm struggling with a problem. Is there a way, to get the creation date information from a NSImage using Swift? I couldn't find a way to do this. And is there a way to get other metadata (exif) from a NSImage as well?

Thank you!


Solution

  • If you mean a file creation date, not all images are associated with files and even those that are don't expose an API for querying what that file is or any information about it.

    For the EXIF data, you can iterate over the representations of the image. If any of them are of class NSBitmapImageRep, you can query rep.valueForProperty(NSImageEXIFData) to get a dictionary of EXIF key-value pairs. The keys are documented here. Note that an image may have no bitmap image reps, may have one, or may have multiple. It's up to you to figure out what to do in each case.