Bushes Bushes -3 years ago 121
Objective-C Question

Self pointer, using with C++ from Objective C

I am having a slight confusion with the self pointer. I understand that if I want to use self in objective C, I need to pass it as a parameter e.g.

someFunction(id self)
{

}


What I'm slightly confused about however is that if I want to use self's member variables, I get the following error

Property 'browser' not found on object of type '__strong id'.

I've defined browser in my header file as:

@property webBrowser* browser;


I am then trying to call a function of my webBrowser class in my c++ function:

[self.browser StartSearch:self];


The error occurs in the line above. The function is definitely called correctly if I instead pass self's member variable as a parameter instead. This feels rather hacky though.

Any explanation as to why it doesn't work and what an alternative would be, would be great.

Answer Source

In order to use property syntax with dot, you need to provide the compiler with the exact type, for example by casting the id pointer to the type of your class. If you do not want to use the exact type or cast, use method call syntax:

[[self browser] StartSearch:self];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download