0

I tried doing this in my objective C method

my_function(self);

my_function(void *param)
{

id self = param;
[self.Output insertText:@"Hello world"];

}

Output is of type NSTextView.

I get the following errors in compilation

Use of undeclared identifier 'id' in the line  "id self = param". 

I tried #import <Cocoa/Cocoa.h>, but didn't help. In the line [self.Output insertText:@"Hello world"];, I get "Expected expression" error.

Basically, what i am trying to do is to share some data periodically between my c function(where it's generated) and objective c method(where it's processed and displayed). I am total newbie in objective c, any help is greatly appreciated. If there is a better way to do this than calling objective c methods from C function, I am open to that.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
qwkslvr
  • 13
  • 3
  • Is this code in a `.m` file or a `.c` file? It needs to be in a `.m` file. And don't name your variable `self`. That is a reserved word. – rmaddy Nov 04 '13 at 17:33
  • 2
    @rmaddy `self` is not a reserved word. Inside a method, it is a variable that is defined for you automatically, but even there you can redeclare it in a nested scope. – rob mayoff Nov 04 '13 at 17:35
  • 2
    @robmayoff OK. It seems you are right. Personally I would avoid its use since it when I see `self` I assume that it is a reference to the current object instance. – rmaddy Nov 04 '13 at 17:43
  • The "undeclared identifier" error strongly suggests that you're not in a .m or .mm file but in a .c file. You can freely code C code in a .m file, but not so Objective-C in a .c file. – Hot Licks Nov 04 '13 at 18:28

1 Answers1

1

You can not use objektive-c in .c files. But you can use c in .m files so if you need to mix make sure its a .m file.

Peter Segerblom
  • 2,773
  • 1
  • 19
  • 24