I have the following problem that I do not succeed to solve. Your help will be appreciated.
To calculate a md5 from a NSS tring, a category has been defined by :
@interface NSString (MD5)
- (NSString *)MD5String;
@end
#import <CommonCrypto/CommonDigest.h>
#import "NSString-md5.h"
@implementation NSString(MD5)
- (NSString *)MD5String
{is
const char *cstr = [self UTF8String];
unsigned char result[16];
CC_MD5( cstr, strlen(cstr), result );
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
#import "NSString-md5.h"
...
NSLog(@"1 %@ ",message.text);
[message.text MD5String];
aborts with error message :
2013-03-03 19:06:14.104 coffreFort[1230:11303] 1 aze
2013-03-03 19:06:22.777 coffreFort[1230:11303] -[__NSCFString MD5String]: unrecognized selector sent to instance 0x71e62b0
2013-03-03 19:06:22.777 coffreFort[1230:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString MD5String]: unrecognized selector sent to instance 0x71e62b0'
message.text is an IBOutlet defined by
@property (weak, nonatomic) IBOutlet UITextField *message;
It's an issue with CLANG (which they promised would be fixed) where categories often go unloaded, especially in the context of frameworks or libraries.. You have to pass in the linker flags -all_load (or -force_load) in addition to -ObjC to force the linker to include them with your binary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With