简体   繁体   中英

Objective-c calling C function

Hello i want to call ac Function from an objective c method how can i do that?

here is my function

static BOOL test () {

....


if(...){
 return YES;
}else{
 return NO;
}
....
}

Just as you will in a C program:

-(void) myVoidMethod {
    BOOL res;
    res = test();
}

Don't forget to declare / include relevant header (again, just like in a C program).

Also, as daknøk mentioned, Objective-C is a strict superset of C, so what works with C - works with Objective-C.

you can call c functions from object-c function in the fallowing way...

-(void)viewDidLoad
{
  // calling the c function from objective-c function 

    someFunctionName();
}

this is my object-c function

void someFunctionName()
{
  // write logic what you want in this function...

  int a ,b;
  a=10;
  b=20
 printf("A value is %d \n B value is %d",a,b);


}

this is my c function ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM