How to get the date from a NSImage - swift

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!

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.

Related

How can you add custom metadata to a video (.mov, .mp4) with AVFoundation?

Although this question has been asked before, I still have not found a single working example of how to do this.
I have a golf swing analysis app that allows the user to save 10 positions in the videoclip that can be navigated to with a shortcut. Until now I have saved the position data separately from the video-file, which is less than ideal for obvious reasons, so I would like to save the position data as metadata in the video-file.
Can anyone give me a working example of saving a String (I'll use Codable to encode the data structure which is not very large) to a custom metadata key (ex. "posi") given an AVAsset?

How to retrieve data from Parse

Using the parse how to retrieve the data to the table view controller if multiple objects are present.
I tried using the query where receptionist equal to current user.
And I tried find objects in background and append it to an array.
But the problem is all the object values appending to the same array.
Read through the Parse IOS Developer's Guide. It has the information & explanations you need to do this.
http://parseplatform.org/docs/ios/guide/
Also, what you're asking really isn't too clear. Try to specify what specific issues you are having along with posting your actual code next time.

How do I obtain a hash of the payload of a digital photo container, ideally in Java?

I have edited EXIF properties on digital pictures, and would like to be able to identify them as identical. I believe this implies extracting the payload stream and computing a hash. What is the best way to do this, ideally in the Java language, most ideally in Java using a native implementation for performance.
JPEG files are a series of 'segments'. Some contain image data, others don't.
Exif data is stored in the APP1 segment. You could write some code to compare the other segments, and see if they match. A hash seems like a reasonable approach here. For example, you might compare a hash of only the SOI, DQT or DHT segments. You'd need to experiment to see which of these gives the best result.
Check out the JpegSegmentReader class from my metadata-extractor library.
Java: https://github.com/drewnoakes/metadata-extractor
.NET: https://github.com/drewnoakes/metadata-extractor-dotnet
With that class you can pull out specific segment(s) from a JPEG for processing.
Let us know how you get on!

How to save / reload a custom array to a plist

I'm loading in data from an sqlite database, storing the values i load from there in the instance variables of a custom class, and then adding this class to a mutable array, which i'm then assigning to the instance variable of my view controller, for use in a tableview.
I would, though, like to save this array into a .plist file in the documents directory on the app's first run, so that i can retrieve the whole object from there on load, rather than pulling all 214 items from the database.
Is this approach a better option? if so, could someone please help provide me with some code that will allow me to save an array of my custom classes as a .plist file? I've come across a lot of sample code on the web, but none of it works correctly.
I'd like to:
Check for the existence of the my_data.plist file.
If it exists, read it in as the array.
If it doesn't, read the data from the sqlite db into an array.
save this data to a .plist so that it can be read in faster later.
Thanks guys, appreciate any help you can give me.
It will probably be faster to just get the values from your database on launch. There will almost definitely be more cost to parse a plist containing these values than to just get them all from the database, unless the query you have to use to get them from the database is really slow.
Note also that once you're saving these objects to a plist on disk, you're actually going to be hurting performance of your program because you'll be writing your objects to disk twice and reading them from disk twice. You'll also be introducing opportunities for discrepancies between the plist and the database in the event of a bug or a crash.
That said, the only way to prove this to yourself may be to implement and profile both options, and compare actual numbers. Check out #occulus's link, above, for instructions how to read and write a plist. To profile your app, try using Instruments
When I google for "nsarray writetofile custom object" (no quotes) and click on the first link in the results, I find a really useful page.
For the record, it's this:
http://www.cocoabuilder.com/archive/cocoa/240775-saving-nsarray-of-custom-objects.html

Property Lists: How to use it to provide easy exchangeable default data to the user?

I want to ship some default data with my app. This data can be stored perfectly in a property list. The strucure is simple:
Root
0
animalType = cat
animalName = Tom
1
animalType = dog
animalName = Rambo
I thought: When I use a property list rather than hard-coding it somewhere, then I could easily provide more defaults to choose from after the app is distributed already. If I would hard-code it, I would have to provide heavy upgrades every time, and Apple would take weeks to let them pass.
But there's one thing I don't get. I make that property list manually in Xcode and put that in my Resources group. As far as I know, Xcode would compile it into some binary format. In my app I would use NSPropertyListSerialization to create a NSDictionary out of it. But this property list would not get placed into the documents directory of the sandbox, right? So if the application would download an update of that property list some time in the future, the update would have to go into documents dir, but the app would still look at the old plist in the root, right? Where to put it? Must I copy it to documents, just like an sqlite database?
And the other thing: When I edit the plist and provide the whole thing as an XML for download/update from a server, then of course that thing would not be "compiled" into some binary format. How would that work? Would NSPropertyListSerialization have trouble reading it? Must I compile that thing every time with XCode and let the app download some binary stuff?
There are two commonly used property list formats: proprientary binary format and xml format (DTD). You can use either of them, and NSPropertyListSerialization will detect automatically, which one is used for your data when de-seralizing.
XML format is more verbose, but it's simple to generate. If you're publishing data from server, you might consider generating xml plist, and compress it with gzip or something.
Now to your first question about where to store the data. To make application payload smaller you might first check documents directory for updated plist, and if it is not present - load default plist from your application bundle.
One general approach used is to always copy plists or other updated elements into the application documents directory - then you just always load from there, and replace when there is an update.
Or you could pre-load the data into a database, download plist updates and refresh the database entries at that time.