Browse files

Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…

… recursion.

git-svn-id: svn:// 378c4bed-2673-4746-83ae-d22ddc8c5b7c
  • Loading branch information...
uli committed Oct 10, 2009
1 parent 7c5ac07 commit f8692e7efd29f58203cf14f5924e32674d886bb2
Showing with 23 additions and 4 deletions.
  1. +23 −4 UKHelperMacros.h
@@ -43,12 +43,31 @@
#define CREATE_AUTORELEASE_POOL(pool) NSAutoreleasePool* (pool) = [[NSAutoreleasePool alloc] init]
#define ASSIGN(targ,newval) do {\
- id __UKHELPERMACRO_OLDTARG = (id)(targ);\
+ NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
(targ) = [(newval) retain];\
} while(0)
-#define DESTROY(obj) do {\
- [obj release];\
- obj = nil;\
+#define DESTROY(targ) do {\
+ NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
+ (targ) = nil;\
} while(0)
+// The following macro is for specifying property (ivar) names to KVC or KVO methods.
+// These methods generally take strings, but strings don't get checked for typos
+// by the compiler. If you write PROPERTY(fremen) instead of PROPERTY(frame),
+// the compiler will immediately complain that it doesn't know the selector
+// 'fremen', and thus point out the typo. For this to work, you need to make
+// sure the warning -Wunknown-selector is on.
+// The code that checks here is (theoretically) slower than just using a string
+// literal, so what we do is we only do the checking in debug builds. In
+// release builds, we use the identifier-stringification-operator "#" to turn
+// the given property name into an ObjC string literal.
+#if DEBUG
+#define PROPERTY(propName) NSStringFromSelector(@selector(propName))
+#define PROPERTY(propName) @#propName

0 comments on commit f8692e7

Please sign in to comment.