Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-26-2009, 02:28 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
Scuba is on a distinguished road
Default Don't really get C Functions in Objective-C

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?

Code:
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!
Scuba is offline   Reply With Quote
Old 03-26-2009, 03:11 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
Scuba is on a distinguished road
Default

I did some searching, and thought using CFStringRef instead of NSString for the return type would work, but it didn't. Any ideas?
Scuba is offline   Reply With Quote
Old 03-26-2009, 03:17 PM   #3 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
PhoneyDeveloper is on a distinguished road
Default

If I compile that function in a .m file it compiles without warnings. Are you trying to compile it in a .c file?
PhoneyDeveloper is offline   Reply With Quote
Old 03-26-2009, 03:56 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
Scuba is on a distinguished road
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
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.
Scuba is offline   Reply With Quote
Old 03-26-2009, 04:41 PM   #5 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
PhoneyDeveloper is on a distinguished road
Default

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.
PhoneyDeveloper is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 332
4 members and 328 guests
blueorb, guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:49 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0