user567
user567

Reputation: 3852

"implicit declaration of function" error in Objective-C

i want to convert a short string to md5 hash , I found several post about it but noone worked. it's the simplest example that I found . i have this error

implicit declaration of function CC_MD5 is invalid in C99

- (NSString *) md5:(NSString *) input
{
 const char *cStr = [input UTF8String];
 unsigned char digest[16];
 CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call

 NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];

 for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
 [output appendFormat:@"%02x", digest[i]];

 return  output;
 }

UPDATE i added #import , it work fine when i call the method like this :

[self md5:@"admin"];

, i get the right md5 hash. But when i do this

 [self md5:userId];

i get an error ,

[NSDecimalNumber UTF8String]: unrecognized selector sent to instance 0x4d3e280 But userId is not decimal , he contain facebook id , but it's declared as NSString

NSString *userId;
@property(retain,nonatomic) NSString *userId;

Upvotes: 7

Views: 7699

Answers (3)

Suhail Patel
Suhail Patel

Reputation: 13694

You need to include the CommonDigest Header file from the Crypto library at the top of your class where the MD5 function is defined as well as include the Security Framework

#import <CommonCrypto/CommonDigest.h>

Upvotes: 3

zaph
zaph

Reputation: 112857

Because the declaration of CC_MD5 has not been seen.

Include the security framework in your project and

#import <CommonCrypto/CommonDigest.h>

Upvotes: 26

A Salcedo
A Salcedo

Reputation: 6478

Are you importing the right interface that defines CC_MD5?

#import "CommonDigest.h"

Upvotes: 0

Related Questions