Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Don't really get C Functions in Objective-C

ScubaScuba Posts: 208Registered Users
edited March 2009 in iOS SDK Development
I haven't done anything in C for many years. But I've gotten into Objective-C easily and I think its great. However, even trying to embed a simple C function is something I can't get to work. This gives me a compiler error of "Conflicting Types", does anyone know what I'm doing wrong?
NSString* testStringFunction(NSString *in) {
	return [in stringByReplacingOccurrencesOfString:@"a" withString:@"b"];
}

... somewhere else in a Obj-C selector ...
NSLog(testStringFunction(@"This 'a' should be a 'b' now."));

Thanks!
Post edited by Scuba on

Replies

  • ScubaScuba Posts: 208Registered Users
    edited March 2009
    I did some searching, and thought using CFStringRef instead of NSString for the return type would work, but it didn't. Any ideas?
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited March 2009
    If I compile that function in a .m file it compiles without warnings. Are you trying to compile it in a .c file?
  • ScubaScuba Posts: 208Registered Users
    edited March 2009
    If I compile that function in a .m file it compiles without warnings. Are you trying to compile it in a .c file?

    The function compiles for me. But oddly, when I add the next line with the NSLog a compiler error shows up near the function. And nope, its in a .m with my obj-c code.
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited March 2009
    That works for me too with no problems.

    What's an 'Obj-C selector'? Do you mean method?

    I built a Nav-Based App from template.
    I opened up the AppDelegate file.
    I pasted in your C function at the top of the file.
    I pasted in the NSLog call inside applicationDidFinishLaunching:
    It then compiled without warnings.
Sign In or Register to comment.