I really don’t know how it is possible but I am checking two files for their MD5 hashes, so I can determine if they are the same or not.
The problem is that the local file (the file stored in the app bundle) gives the correct value and the one stored on online server is giving bad value. However, if I check the md5 of the online file in Terminal on Mac, or by some internet tool, it gives the correct value.
How is this possible?
This is basically what I am doing.
NSData *currencyData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.iworldtip.com/appl/texts/files/CountryCurrency.plist"]];
NSData *localCurrencyData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"CountryCurrency" ofType:@"plist"]];
NSString *currencyDataHashValue = [currencyData md5];
NSString *localCurrencyDataHashValue = [localCurrencyData md5];
if (![currencyDataHashValue isEqual:localCurrencyDataHashValue]) {
NSLog(@"Saving new version of currency plist\n\n%@ - %@", currencyDataHashValue, localCurrencyDataHashValue);
...
...
Here is the output:

This is the md5 extension which I am using (found somewhere online):
.h file:
@interface NSString (MyExtensions)
- (NSString *) md5;
@end
@interface NSData (MyExtensions)
- (NSString*)md5;
@end
.m file:
#import "md5Extension.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (MyExtensions)
- (NSString *) md5
{
const char *cStr = [self UTF8String];
unsigned char result[16];
CC_MD5( cStr, strlen(cStr), result ); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
@implementation NSData (MyExtensions)
- (NSString*)md5
{
unsigned char result[16];
CC_MD5( self.bytes, self.length, result ); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
So, I found out where the problem was.
First thing is, that I am dumb. I was looking at the output and thought that the problem was the remote file, but the wrong hash was given by the local file!
Next thing is, that this was caused by a conversion which Xcode does automatically when compiling the project – it converts the XML Plist file to a Binary Plist file. Thus it has a different MD5 hash.
So the final solution was to convert those remote files to Binary Plists and everything works like a charm!
PS: I found a great tool for editing Plists – it is called PlistEdit Pro.
It can do everything you can imagine with the Plists – converts them to binary and vice versa… (I know it can be done in Terminal by plutil, but this is a more convenient solution)