I'm sure I'll get 20 people saying "why would you want to do that anyways"... but, I'm going to ask my question none-the-less because it's somewhat academic in nature.
I'd like to use C macros to redefine [ClassName new]
into something like: new(ClassName)
, and I'm wondering how to do this. I'm not super comfortable with C macros to begin with (I know - embarrassing - I should be) - and I'm definitely not comfortable mixing them in with my Objective-C code. So, on with the question...
First, being it's a preprocessor thing, can I do a simple substitution like such:
#define new(x) [x new]
or, for whatever reason, do I need to drop down to the objective-c runtime, and do something more akin to:
#define new(x) objc_msgSend(class_createInstance(x, 0), sel_registerName("init"))
What are the downfalls of doing something like this?
Is this kind of thing used often by others, or, would someone look at it and say "what the heck are you doing there"? (and should I care)
Thanks
EDIT:
It occurred to me after posting this, that I have, in fact, see this kind of thing before - in the Three20 lib, where they do things like this:
#define TT_RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
#define TT_INVALIDATE_TIMER(__TIMER) { [__TIMER invalidate]; __TIMER = nil; }
// Release a CoreFoundation object safely.
#define TT_RELEASE_CF_SAFELY(__REF) { if (nil != (__REF)) { CFRelease(__REF); __REF = nil; } }
So probably my question becomes simply; What are the downfalls of doing this, and is it a relatively accepted practice, or something that's going to get me into more trouble than it's worth?