-1

I have one temp.mm class which contains implementation for test class & extern "C" class. I am trying to call objective-c method in extern "c" class(i.e. testMethod & testMethod1). How can i call objective-c method in extern "C" class function?.

I am new to Objective-c

I mention the example code below..

import<test.h>
@implement test

-(void)testMethod
{
//code
}

-(NSString*)testMethod1:(NSString *)value
{
   //code
   return value;
}

void callMethod()
{
   how to call testMethod & testMethod1 in this also?
}

@end

extern "C"
{
how to call testMethod & testMethod1?
}
d4Rk
  • 6,622
  • 5
  • 46
  • 60
VPS
  • 37
  • 1
  • 12

2 Answers2

2

The C code part is (and must be) outside your class' implementation, so you'll have to create an object of test and then call it's methods, like follows:

void callMethod() 
{
    test *test = [[test alloc] init];
    [test testMethod];

    const char *yourCString = "yourCString";
    [test testMethod1:[NSString stringWithCString:yourCString encoding:NSUTF8StringEncoding]];
}

You don't need the extern "C" part in the implementation (.m or .mm files), this is just needed in the header (.h files) when you want to mark them as "plain old c code" (not C++).

See: Is it required to add 'extern C' in source file also?

Community
  • 1
  • 1
d4Rk
  • 6,622
  • 5
  • 46
  • 60
  • thank you...i am trying to crate plugin for unity3d, because of that i want extern "C" part in implementation........that plugin contains web service(svc service) communication.... – VPS Jul 20 '15 at 06:18
  • Ok, so why didn't you mention this in the first place? So I think you are looking for this: http://stackoverflow.com/a/30946257/2019384 – d4Rk Jul 20 '15 at 06:39
-1

too call the method at initial ..... use: [self testmethod]; [self testmethod1]; if you like to inherit this method in to another class just import the .m file.

Kishore kumar
  • 143
  • 1
  • 14