I’m binding a ObjC library and it all works well, but I have one problem.
The ObjC library is using some values that are defined in a separate header.
For example, a header with:
#define SOME_PROPERTY_1 TRUE
#define SOME_PROPERTY_2 TRUE
#define SOME_PROPERTY_3 FALSE
Dependant on these properties, the library will make some changes to the view (so these changes are in the library, not in my C# code).
I would like to have access to these properties from my C# code so that I can change them. Now I need to build my library again if I want to change them and I can’t change them dynamically (what the goal is).
Is this possible?
I have searched on this, but I didn’t understand the two proposed solutions:
- Putting them in my C# code instead of in my binding
-> I assume this is not a solution, because in that case the library will not know about these changes? (no connection) - Binding them as (static) properties
Unfortunately, I don’t know how to do this. In this header, these is no Class/Interface, only #DEF statements, so I don’t know in which ‘class’ I should define these properties.
The header is then included in some other ObjC classes. I was trying to see if I could define them there, but it’s an interface and properties are not accepted.
So basically, there is a “SomeController” class that I’m binding and the “SomeController.h” is defined as interface
@interface SomeController : UIViewController
And in the “SomeController.m” you then have
#import "Constants.h" //The file with only #DEF statements
@implementation SomeController
{
...
}
Any ideas?
Regards,
Matt
This is not possible, because your SOME_PROPERTY_# aren’t actually variables, they’re preprocessing directives.
This means that the ObjectiveC preprocessor will replace all instances of SOME_PROPERTY_# in your source code with the value you defined it to be, but there is no SOME_PROPERTY_# variable/constant in the final executable.
For example:
will be converted to this by the preprocessor:
As you can see there is no SOME_PROPERTY_1 in the converted source code.
This means that you can’t change the value of SOME_PROPERTY_# dynamically.