Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing C and objective-C

Tags:

c

objective-c

I've been using objective C for a while now, and I've started learning some of the lower level iPhone API's such as core audio. Most of these API's are in C which is confusing me a bit, I'm not sure where to put a lot of code and I don't know the rules, etc. Does anyone know where a good place to start learning this is?

Thanks, Darren.

like image 879
Darren Findlay Avatar asked Feb 28 '11 19:02

Darren Findlay


People also ask

Which is faster C or Objective-C?

Objective-C is slightly slower than straight C function calls because of the lookups involved in its dynamic nature.

Is Objective-C derived from C?

Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.

Why is Objective-C important?

One of the major benefits of Objective-C is the easy access to C and C++ functions and libraries. For example, making API calls with Objective-C may feel more intuitive to C and C++ veterans.


2 Answers

You can write C inline inside any Objective C method. You can also define functions in a .c file and their prototypes in a .h file which you can then include into any ObjectiveC .m file and call from within Objective C code.

like image 108
Dad Avatar answered Sep 30 '22 11:09

Dad


Does anyone know where a good place to start learning this is?

  1. Buy and read "The C Programming Language". It's not very long and surprisingly enjoyable.
  2. Read and understand Apple's C-based example code.
  3. Browse the header files for Apple's classes. This is a great way to learn how apple sets up enums and string constants, etc.

Doing these three things won't make you an expert in C, but it'll give you 90% of what you need to be able to confidently get things done with Apple's low level frameworks.

like image 39
kubi Avatar answered Sep 30 '22 10:09

kubi