I am creating an Objective-C program that when calling a C function, it will try to convert a number and return a string. However this caused an Apple Mach-O Linker (ld) Error when I tried to compile.
Here's the code snippet:
NSString * convertNum (int theNum) {
NSString *numString;
switch (theNum) {
case 102:
numString = @"Oh yea, string 102";
break;
case 104:
numString = @"Oh great, string 104";
break;
/* ... */
default:
numString = @"Don't feed me with something I don't know!";
break;
}
return numString;
}
Did I do anything wrong? I am using Xcode 4. Thank you very much.
Linking error usually means something like a method, function or something similar has the prototype declare but it is not implemented anywhere. It can also mean you have not included a library or framework in you application but you are using the header files from that library or framework.
Also your use of numString is fine, you are returning pointers to strings that are static, they generated at compile time.