I want to use these lines of code from this source
#define TEXTVIEW_SET_HTML_TEXT(__textView__, __text__)\
do\
{\
if ([__textView__ respondsToSelector: NSSelectorFromString(@"setContentToHTMLString:")])\
[__textView__ performSelector: NSSelectorFromString(@"setContentToHTMLString:") withObject: __text__];\
else\
__textView__.text = __text__;\
}\
while (0)
#define TEXTVIEW_GET_HTML_TEXT(__textView__, __text__)\
do\
{\
if ([__textView__ respondsToSelector: NSSelectorFromString(@"contentAsHTMLString")])\
__text__ = [__textView__ performSelector: NSSelectorFromString(@"contentAsHTMLString") withObject: nil];\
else\
__text__ = __textView__.text;\
}\
while (0)
What should I do? I am new to macros. Should i define a uitextview variable with name __textView__?? Is it possible to help me with some basic steps in order to use this code?
You just have to put your macros outside your
@implementation, something like this:You don’t have to declare the variables, as these are already declared in the macro. You can think of this:
as this C-style function:
The difference is that if you have declared it as a C-style function, it would be included in your app when it is compiled/linked. However, since it was
#defined, it means the compiler would change it first to thedo-whilebefore compiling.You would call it like this:
As an additional info,
#defineis usually used to define constants, something like:which would have to be called something like:
But as seen in the macro, it can also look/be used as a function. Thus, you have to consider how the macro/
#definelooks like to be sure that you call it properly.