Permalink
Browse files

update collectionUtils to latest (arc compatible)

  • Loading branch information...
1 parent 5acc7c0 commit b8d69f7402a12d233aadf346b365df6633730e8b @steipete committed Dec 15, 2011
Showing with 45 additions and 23 deletions.
  1. +44 −22 Categories/NSArray/MACollectionUtilities.h
  2. +1 −1 Categories/NSArray/MACollectionUtilities.m
@@ -2,18 +2,40 @@
// MACollectionUtilities.h
// MACollectionUtilities
//
-// MMACollectionUtilities is distributed under a BSD license, as listed below.
-// Copyright (c) 2010, Michael Ash
-// All rights reserved.
-// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-// Neither the name of Michael Ash nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// https://github.com/mikeash/MACollectionUtilities
+// Created by Michael Ash on 10/11/10.
+// Copyright 2010 Michael Ash. All rights reserved.
+//
+/*
+ MMACollectionUtilities is distributed under a BSD license, as listed below.
+
+
+ Copyright (c) 2010, Michael Ash
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+ Neither the name of Michael Ash nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#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__)])
@@ -49,17 +71,17 @@
// ===========================================================================
// 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; \
- __typeof__(__VA_ARGS__) MA_retval = __VA_ARGS__; \
- if(MA_eachTable) \
- CFRelease(MA_eachTable); \
- return MA_retval; \
- }())
-
-static inline NSDictionary *MADictionaryWithKeysAndObjects(id const *keysAndObjs, NSUInteger count)
+(void)MA_eachTable; \
+__typeof__(__VA_ARGS__) MA_retval = __VA_ARGS__; \
+if(MA_eachTable) \
+CFRelease(MA_eachTable); \
+return MA_retval; \
+}())
+
+static inline NSDictionary *MADictionaryWithKeysAndObjects(id *keysAndObjs, NSUInteger count)
{
id keys[count];
id objs[count];
@@ -87,11 +109,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];
-}
+}
@@ -73,4 +73,4 @@ - (id)ma_match: (BOOL (^)(id obj))block
return nil;
}
-@end
+@end

0 comments on commit b8d69f7

Please sign in to comment.