1

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)

1
  • 3
    click1 click2 Commented Aug 4, 2017 at 9:21

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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];

}

Comments

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
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.