I'm very new to Xcode and objective C, I know the basics but I was wondering if you can implement normal C code into objective C in Xcode, I saw somewhere that you can create a C header file and implement that into Xcode?? if that's possible, how would you do that, i'm not very experienced with headers. If that completely wrong I would generally just like to know how to call C functions in objective C (Xcode)
Asked
Active
Viewed 589 times
1
-
3[click1](https://stackoverflow.com/questions/2193826/using-a-c-function-in-objective-c-for-iphone) [click2](https://stackoverflow.com/questions/801976/mixing-c-functions-in-an-objective-c-class) – kocica Aug 04 '17 at 09:21
3 Answers
3
You don't even have to put your C code in a different file, you can simply just write C code in your .m
file. The Objective-C compiler accepts C code.
If, at a later time, you would like to figure out how to separate your code into different files and use header files, you can do that too.

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
1
Objective c can call C in-line. For instance:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext(); //result of a C method
[self drawRoundedRectWithContext:context withRect:rect];
}
0
Try with this way.
void *refToSelf;
int cCallback()
{
[refToSelf someMethod:someArg]; // here objective-c method is calling in c.
}
@implementation SomeClass
- (id) init
{
self = [super init];
refToSelf = self;
}
- (void) someMethod:(int) someArg
{
}

Shah Nilay
- 778
- 3
- 21