Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… recursion.

git-svn-id: svn://witness.is-a-geek.org/svn@30 378c4bed-2673-4746-83ae-d22ddc8c5b7c
  • Loading branch information...
commit f8692e7efd29f58203cf14f5924e32674d886bb2 1 parent 7c5ac07
uli authored
Showing with 23 additions and 4 deletions.
  1. +23 −4 UKHelperMacros.h
View
27 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];\
[__UKHELPERMACRO_OLDTARG release];\
} while(0)
-#define DESTROY(obj) do {\
- [obj release];\
- obj = nil;\
+#define DESTROY(targ) do {\
+ NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
+ (targ) = nil;\
+ [__UKHELPERMACRO_OLDTARG release];\
} 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))
+#else
+#define PROPERTY(propName) @#propName
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.