Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 966
Bushes Avatar asked Dec 16 '25 17:12

Bushes


1 Answers

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];
like image 65
Sergey Kalinichenko Avatar answered Dec 19 '25 11:12

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!