#Define binding is used as a constant

The code I'm trying to link puts a very important key in one of the .h files:

#define xAppKey @"REPLACE_WITH_YOUR_APP_KEY" 

This value is then reused in the ObjC code. I suspiciously that during the binding process this value is not executed. Based on several other SO threads, this seems to be the case, at least. Is my problem likely something else, or is there a chance that this value is not respected in the wrapped code?

Sorry if my objective-c terminology is off, I don't know anything about this.

EDIT

I just wanted to clarify what might not have been obvious. By "bind" I mean bind it to monotouch as a native library. If it was already clear, go on ...

+1
source share
2 answers

The point of having #define in Obj-C .h is to let it replace an application using the library. In this case, your library (Obj-C) is probably distributed only as sources.

But you want to create bindings for it (Xamarin.iOS). Therefore, you need to compile this library, and compilation will fix the xApiKey value once and for all.

Your goal is probably to expose this xApiKey for the consumer application through Xamarin.iOS. You will need to modify the Obj-C library to use a property instead of a constant, and then bind the (static) property attributes through Xamarin.iOS

+2
source

xAppKey is a macro. It will not be connected at all. On the contrary. At compile time, it will be replaced by @"REPLACE_WITH_YOUR_APP_KEY" , and then compiled as if this line has been repeated all the time.

For this reason, some experts suggest replacing them with constant lines. These experts may be right. However, I like #define.

And for this reason you should not add comments to the #define statement.

 #define xAppKey @"REPLACE_WITH_YOUR_APP_KEY" // This is the application key 

Such things will almost certainly cause compile-time errors that can be difficult to understand. Example:

 NSLog (@"%@", xAppKey); 

This works fine with a comment because it will be converted to:

 NSLog (@"%@", @"REPLACE_WITH_YOUR_APP_KEY"); 

But with a comment, it will be converted to:

 NSLog (@"%@", @"REPLACE_WITH_YOUR_APP_KEY" // This is the application key); 

And it does not compile.

+4
source

All Articles