Skip to content

Instantly share code, notes, and snippets.

@djfumberger
Created September 4, 2014 07:50
Show Gist options
  • Save djfumberger/9f766a09e06c07e17ca8 to your computer and use it in GitHub Desktop.
Save djfumberger/9f766a09e06c07e17ca8 to your computer and use it in GitHub Desktop.
- (NSString *)hashForObject:(NSObject*)object {
// Archive data
NSData *d = [NSKeyedArchiver archivedDataWithRootObject: object];
// Create MD5
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(d.bytes, d.length, md5Buffer);
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x",md5Buffer[i]];
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment