Protected Property in Objective-C
Objective-C do not have protected property. The ivars are protected by default, but you still have to declare them in interface file in order to expose those variables. However, that is not what I can use. Because in the case that my private variables are cpp class but I can only expose .h to the header to Swift.
Protected Property
Objective-C do not have protected property. The ivars are protected by default, but you still have to declare them in interface file in order to expose those variables. However, that is not what I can use. Because in the case that my private variables are cpp class but I can only expose .h to the header to Swift.
So Another work around to expose the parent private methods to child classes are using a second header file.
Solution
In Parent.h
1 | @interface Parent : NSObject |
In Parent.mm
1 |
|
In Child.h
1 |
|
In Child.mm
1 |
|
Above is an example I am going to use. Assume we have some property for Parent that I want to expose to Child only which are protected properties. Here is a step by step solution on how to achieve this.
Create a Second Header For Parent
First step is to create a second Header file for parent.
In Parent_Protected.h
1 |
|
Import into Parent
Import the second header file in Parent.mm
In Parent.mm
1 |
|
Import into Child
Import the second header file in Child.mm
In Child.mm
1 |
|
Note that you need to use [super xxx] to access the property. If you use _xxx it may end up complain Use of undeclared identifier.
