When doing objective-c, do I have to write out functions like:
- (int) someFunction: (int) a someParam: (int) b;
Or can I use regular C style:
void someFunction(int a, int b);
If I can do the C style, is there any benefit to doing it in the Objective-C style?
You can use regular C functions, if you like, since Objective-C is just a super set of C.
You need to use Objective-C syntax if you want to use Objective-C features, like classes, messages, inheritance, etc... and of course to use the Cocoa/CocoaTouch SDK.
You can mix Objective-C and C code in your files, and have an Objective-C method call out to a pure C function. You can also call an Objective-C method from a pure C function by accessing directly the Objective-C runtime layer (e.g., using the objc_msgSend
function).
That's not an Objective-C function, it's a method. It's got access to an instance's variables and other methods. The two are not equivalent. In most cases you should use an Objective-C method. Why do you want to use C functions? What are you trying to do?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With