Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for ARC

Modify code to compile under ARC & non-ARC; works when using GCC
  • Loading branch information...
commit 5501d5aeca231d634d3cd2433b61c07a6e3a5008 1 parent c4e5900
@Orangenhain Orangenhain authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 MACollectionUtilities.h
View
17 MACollectionUtilities.h
@@ -8,6 +8,17 @@
#import <Foundation/Foundation.h>
+// make sure non-Clang compilers can still compile
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+// no ARC ? -> declare the ARC attributes we use to be a no-op, so the compiler won't whine
+#if ! __has_feature( objc_arc )
+#define __autoreleasing
+#define __bridge
+#endif
+
#define ARRAY(...) ([NSArray arrayWithObjects: IDARRAY(__VA_ARGS__) count: IDCOUNT(__VA_ARGS__)])
#define SET(...) ([NSSet setWithObjects: IDARRAY(__VA_ARGS__) count: IDCOUNT(__VA_ARGS__)])
@@ -43,7 +54,7 @@
// ===========================================================================
// internal utility whatnot that needs to be externally visible for the macros
-#define IDARRAY(...) ((id[]){ __VA_ARGS__ })
+#define IDARRAY(...) ((__autoreleasing id[]){ __VA_ARGS__ })
#define IDCOUNT(...) (sizeof(IDARRAY(__VA_ARGS__)) / sizeof(id))
#define EACH_WRAPPER(...) (^{ __block CFMutableDictionaryRef MA_eachTable = nil; \
(void)MA_eachTable; \
@@ -81,11 +92,11 @@ static inline id MAEachHelper(NSArray *array, CFMutableDictionaryRef *eachTableP
*eachTablePtr = CFDictionaryCreateMutable(NULL, 0, &keycb, &kCFTypeDictionaryValueCallBacks);
}
- NSEnumerator *enumerator = (id)CFDictionaryGetValue(*eachTablePtr, array);
+ NSEnumerator *enumerator = (__bridge id)CFDictionaryGetValue(*eachTablePtr, (__bridge CFArrayRef)array);
if(!enumerator)
{
enumerator = [array objectEnumerator];
- CFDictionarySetValue(*eachTablePtr, array, enumerator);
+ CFDictionarySetValue(*eachTablePtr, (__bridge CFArrayRef)array, (__bridge void *)enumerator);
}
return [enumerator nextObject];
}
Please sign in to comment.
Something went wrong with that request. Please try again.