tags:

views:

762

answers:

1

Using the iPhone SDK, I'm having the user select images from the image picker. If the user selects an image they've selected before, I'd like to make the user aware of it.

My initial plan (just to make sure other things work for now) is to save the image to a file (need to do this anyway for other reasons), using a checksum of the NSData as the filename. Then, when they select the same image later on, the checksum will be the same and so I can see that a file with that name already exists - hurrah!

However, I've scoured the internet and the Apple docs for how to compute a checksum from a NSData. I know I could implement my own implementation, but I'd prefer to avoid that, if possible. I'm also happy for other ideas of how to check that two UIImages are the same.

+2  A: 

In the <CommonCrypto/CommonDigest.h> header file there should be a CC_MD5 function that will compute an MD5 hash of arbitrary data. It's a C function, so it won't work directly on an NSData, but it should do what you need.

Some more info here (including a wrapper using NSString - should be easy enough to convert to use NSData)

Eric Petroelje
Excellent. Once I get home and am able to do it on NSData, I'll post back here with a code sample. Thanks!
Itay
oops.. must have forgotten to return to post promised samples.
Michael