appjam 0.1.8.6 → 0.1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/lib/appjam.rb +1 -1
  2. data/lib/appjam/generators/blank.rb +133 -0
  3. data/lib/appjam/generators/help.rb +5 -3
  4. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
  5. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  6. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  7. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
  8. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
  9. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
  10. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
  11. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
  12. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
  13. data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
  14. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
  15. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
  16. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
  17. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
  18. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
  19. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
  20. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
  21. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
  22. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  23. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
  24. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
  25. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  26. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
  27. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
  28. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
  29. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
  30. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
  31. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
  32. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
  33. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
  34. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
  35. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
  36. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
  37. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
  38. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
  39. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
  40. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
  41. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
  42. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
  43. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
  44. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
  45. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
  46. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
  47. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
  48. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
  49. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  50. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  51. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
  52. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
  53. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
  54. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
  55. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
  56. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
  57. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  58. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  59. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  60. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  61. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
  62. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
  63. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
  64. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
  65. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
  66. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
  67. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
  68. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
  69. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
  70. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
  71. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
  72. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
  73. data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
  74. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
  75. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
  76. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
  77. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
  78. data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
  79. data/lib/appjam/generators/templates/resources/Default.png +0 -0
  80. data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
  81. data/lib/appjam/generators/templates/resources/contents.tt +4 -0
  82. data/lib/appjam/version.rb +1 -1
  83. metadata +462 -326
  84. data/test/helper.rb +0 -132
  85. data/test/test_model_generator.rb +0 -28
  86. data/test/test_project_generator.rb +0 -38
@@ -0,0 +1,33 @@
1
+ //
2
+ // Mixin.h
3
+ // ObjectiveMixin
4
+ //
5
+ // Created by Vladimir Mitrovic on 24/02/2011.
6
+ // Copyright 2011 Vladimir Mitrovic. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+
11
+
12
+ @interface Mixin : NSObject
13
+
14
+ + (void) from:(Class)sourceClass into:(Class)destinationClass;
15
+ + (void) from:(Class)sourceClass into:(Class)destinationClass followInheritance:(BOOL)followInheritance force:(BOOL)force;
16
+
17
+ @end
18
+
19
+
20
+ // A category on NSObject, for convenience. It uses the Mixin class internally.
21
+ @interface NSObject (Mixin)
22
+
23
+ + (void) mixinFrom:(Class)sourceClass;
24
+ + (void) mixinFrom:(Class)sourceClass followInheritance:(BOOL)followInheritance force:(BOOL)force;
25
+
26
+ - (void) mixinFrom:(Class)sourceClass;
27
+ - (void) mixinFrom:(Class)sourceClass followInheritance:(BOOL)followInheritance force:(BOOL)force;
28
+
29
+
30
+ + (id) allocWithSuperclass:(Class)superClass;
31
+ + (Class) classWithSuperclass:(Class)superClass;
32
+
33
+ @end
@@ -0,0 +1,122 @@
1
+ //
2
+ // Mixin.m
3
+ // ObjectiveMixin
4
+ //
5
+ // Created by Vladimir Mitrovic on 24/02/2011.
6
+ // Copyright 2011 Vladimir Mitrovic. All rights reserved.
7
+ //
8
+
9
+ #import "Mixin.h"
10
+ #import <objc/runtime.h>
11
+
12
+
13
+ @implementation Mixin
14
+
15
+ + (void) mixinFrom:(id)source into:(id)destination force:(BOOL)force {
16
+ unsigned int methodCount = 0;
17
+ Method* methods = class_copyMethodList(source, &methodCount);
18
+ for (int i = 0; i < methodCount; i++) {
19
+ Method m = methods[i];
20
+
21
+ SEL name = method_getName(m);
22
+ IMP imp = method_getImplementation(m);
23
+ const char* types = method_getTypeEncoding(m);
24
+
25
+ if (force) {
26
+ class_replaceMethod(destination, name, imp, types);
27
+ } else {
28
+ // Will fail if method already exists
29
+ class_addMethod(destination, name, imp, types);
30
+ }
31
+ }
32
+
33
+ if (methods) {
34
+ free(methods);
35
+ }
36
+ }
37
+
38
+ + (void) from:(Class)sourceClass into:(Class)destinationClass followInheritance:(BOOL)followInheritance force:(BOOL)force {
39
+ if (followInheritance) {
40
+ // Mixin from all ancestor classes recursively, up to the common ancestor
41
+ Class sourceParent = class_getSuperclass(sourceClass);
42
+ if (sourceParent != nil) {
43
+ // Find a common ancestor for sourceClass and destinationClass
44
+ Class destinationParent = destinationClass;
45
+ while ((destinationParent = class_getSuperclass(destinationParent)) != nil && destinationParent != sourceParent);
46
+
47
+ // Only mixin from sourceParent if it's not an ancestor of destinationClass
48
+ if (destinationParent == nil) {
49
+ [self from:sourceParent into:destinationClass followInheritance:YES force:force];
50
+ }
51
+ }
52
+ }
53
+
54
+ // Mixin instance methods
55
+ [self mixinFrom:sourceClass into:destinationClass force:force];
56
+
57
+ // Mixin class methods
58
+ [self mixinFrom:object_getClass(sourceClass) into:object_getClass(destinationClass) force:force];
59
+ }
60
+
61
+ + (void) from:(Class)sourceClass into:(Class)destinationClass {
62
+ [self from:sourceClass into:destinationClass followInheritance:NO force:NO];
63
+ }
64
+
65
+ @end
66
+
67
+
68
+ @implementation NSObject (Mixin)
69
+
70
+ - (void) mixinFrom:(Class)sourceClass {
71
+ [Mixin from:sourceClass into:[self class]];
72
+ }
73
+
74
+ - (void) mixinFrom:(Class)sourceClass followInheritance:(BOOL)followInheritance force:(BOOL)force {
75
+ [Mixin from:sourceClass into:[self class] followInheritance:followInheritance force:force];
76
+ }
77
+
78
+ + (void) mixinFrom:(Class)sourceClass {
79
+ [Mixin from:sourceClass into:self];
80
+ }
81
+
82
+ + (void) mixinFrom:(Class)sourceClass followInheritance:(BOOL)followInheritance force:(BOOL)force {
83
+ [Mixin from:sourceClass into:self followInheritance:followInheritance force:force];
84
+ }
85
+
86
+ + (Class) classWithSuperclass:(Class)superClass {
87
+ Protocol *protocol = nil;
88
+
89
+ NSString *myClassName = NSStringFromClass(self);
90
+ if([myClassName hasSuffix:@"Mixin"]) {
91
+ protocol = NSProtocolFromString([myClassName substringToIndex:myClassName.length - 5]);
92
+ }
93
+
94
+ Class fromClass = self;
95
+ NSString *dynamicClassName = [NSString stringWithFormat:@"%@_WithSuperclass_%@", NSStringFromClass(fromClass), NSStringFromClass(superClass)];
96
+ if(protocol) {
97
+ dynamicClassName = [NSString stringWithFormat:@"%@_ConformingToProtocol_%@", dynamicClassName, NSStringFromProtocol(protocol)];
98
+ }
99
+
100
+ Class dynamicClass = NSClassFromString(dynamicClassName);
101
+
102
+ if(!dynamicClass) {
103
+ dynamicClass = objc_allocateClassPair(fromClass, [dynamicClassName UTF8String], 0);
104
+
105
+ [Mixin from:fromClass into:dynamicClass];
106
+
107
+ if(protocol) {
108
+ class_addProtocol(dynamicClass, protocol);
109
+ }
110
+
111
+ objc_registerClassPair(dynamicClass);
112
+ }
113
+
114
+ return dynamicClass;
115
+ }
116
+
117
+
118
+ + (id) allocWithSuperclass:(Class)superClass {
119
+ return [[self classWithSuperclass:superClass] alloc];
120
+ }
121
+
122
+ @end
@@ -0,0 +1,72 @@
1
+ //
2
+ // USArrayWrapper.h
3
+ // Underscore
4
+ //
5
+ // Created by Robert Böhnke on 5/13/12.
6
+ // Copyright (C) 2012 Robert Böhnke
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ // of this software and associated documentation files (the "Software"), to
10
+ // deal in the Software without restriction, including without limitation the
11
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
+ // sell copies of the Software, and to permit persons to whom the Software is
13
+ // furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in
16
+ // all copies or substantial portions of the Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ // IN THE SOFTWARE.
25
+ //
26
+
27
+ #import <Foundation/Foundation.h>
28
+
29
+ #import "USConstants.h"
30
+
31
+ @interface USArrayWrapper : NSObject
32
+
33
+ + (USArrayWrapper *)wrap:(NSArray *)array;
34
+
35
+ - (id)init __attribute__((deprecated("You should Underscore.array() instead")));
36
+
37
+ @property (readonly) NSArray *unwrap;
38
+
39
+ @property (readonly) id first;
40
+ @property (readonly) id last;
41
+
42
+ @property (readonly) USArrayWrapper *(^head)(NSUInteger n);
43
+ @property (readonly) USArrayWrapper *(^tail)(NSUInteger n);
44
+
45
+ @property (readonly) NSUInteger (^indexOf)(id obj);
46
+
47
+ @property (readonly) USArrayWrapper *flatten;
48
+ @property (readonly) USArrayWrapper *(^without)(NSArray *values);
49
+
50
+ @property (readonly) USArrayWrapper *shuffle;
51
+
52
+ @property (readonly) id (^reduce)(id memo, UnderscoreReduceBlock block);
53
+ @property (readonly) id (^reduceRight)(id memo, UnderscoreReduceBlock block);
54
+
55
+ @property (readonly) USArrayWrapper *(^each)(UnderscoreArrayIteratorBlock block);
56
+ @property (readonly) USArrayWrapper *(^map)(UnderscoreArrayMapBlock block);
57
+
58
+ @property (readonly) USArrayWrapper *(^pluck)(NSString *keyPath);
59
+
60
+ @property (readonly) USArrayWrapper *uniq;
61
+
62
+ @property (readonly) id (^find)(UnderscoreTestBlock block);
63
+
64
+ @property (readonly) USArrayWrapper *(^filter)(UnderscoreTestBlock block);
65
+ @property (readonly) USArrayWrapper *(^reject)(UnderscoreTestBlock block);
66
+
67
+ @property (readonly) BOOL (^all)(UnderscoreTestBlock block);
68
+ @property (readonly) BOOL (^any)(UnderscoreTestBlock block);
69
+
70
+ @property (readonly) USArrayWrapper *(^sort)(UnderscoreSortBlock block);
71
+
72
+ @end
@@ -0,0 +1,305 @@
1
+ //
2
+ // USArrayWrapper.m
3
+ // Underscore
4
+ //
5
+ // Created by Robert Böhnke on 5/13/12.
6
+ // Copyright (C) 2012 Robert Böhnke
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ // of this software and associated documentation files (the "Software"), to
10
+ // deal in the Software without restriction, including without limitation the
11
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
+ // sell copies of the Software, and to permit persons to whom the Software is
13
+ // furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in
16
+ // all copies or substantial portions of the Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
+ // IN THE SOFTWARE.
25
+ //
26
+
27
+ #import "Underscore.h"
28
+
29
+ #import "USArrayWrapper.h"
30
+
31
+ @interface USArrayWrapper ()
32
+
33
+ - initWithArray:(NSArray *)array;
34
+
35
+ @property (readwrite, retain) NSArray *array;
36
+
37
+ @end
38
+
39
+ @implementation USArrayWrapper
40
+
41
+ #pragma mark Class methods
42
+
43
+ + (USArrayWrapper *)wrap:(NSArray *)array
44
+ {
45
+ return [[USArrayWrapper alloc] initWithArray:[array copy]];
46
+ }
47
+
48
+ #pragma mark Lifecycle
49
+
50
+ - (id)init
51
+ {
52
+ return [super init];
53
+ }
54
+
55
+ - (id)initWithArray:(NSArray *)array
56
+ {
57
+ if (self = [super init]) {
58
+ self.array = array;
59
+ }
60
+ return self;
61
+ }
62
+
63
+ @synthesize array = _array;
64
+
65
+ - (NSArray *)unwrap
66
+ {
67
+ return [self.array copy];
68
+ }
69
+
70
+ #pragma mark Underscore methods
71
+
72
+ - (id)first
73
+ {
74
+ return self.array.count ? [self.array objectAtIndex:0] : nil;
75
+ }
76
+
77
+ - (id)last
78
+ {
79
+ return self.array.lastObject;
80
+ }
81
+
82
+ - (USArrayWrapper *(^)(NSUInteger))head
83
+ {
84
+ return ^USArrayWrapper *(NSUInteger count) {
85
+ NSRange range = NSMakeRange(0, MIN(self.array.count, count));
86
+ NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
87
+ NSArray *result = [self.array objectsAtIndexes:indexSet];
88
+
89
+ return [[USArrayWrapper alloc] initWithArray:result];
90
+ };
91
+ }
92
+
93
+ - (USArrayWrapper *(^)(NSUInteger))tail
94
+ {
95
+ return ^USArrayWrapper *(NSUInteger count) {
96
+ NSRange range;
97
+ if (count > self.array.count) {
98
+ range = NSMakeRange(0, self.array.count);
99
+ } else {
100
+ range = NSMakeRange(self.array.count - count, count);
101
+ }
102
+
103
+ NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
104
+ NSArray *result = [self.array objectsAtIndexes:indexSet];
105
+
106
+ return [[USArrayWrapper alloc] initWithArray:result];
107
+ };
108
+ }
109
+
110
+ - (NSUInteger (^)(id))indexOf
111
+ {
112
+ return ^NSUInteger (id obj) {
113
+ return [self.array indexOfObject:obj];
114
+ };
115
+ }
116
+
117
+ - (USArrayWrapper *)flatten
118
+ {
119
+ __weak NSArray *array = self.array;
120
+ __block NSArray *(^flatten)(NSArray *) = ^NSArray *(NSArray *input) {
121
+ NSMutableArray *result = [NSMutableArray array];
122
+
123
+ for (id obj in input) {
124
+ if ([obj isKindOfClass:[NSArray class]]) {
125
+ #pragma clang diagnostic push
126
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
127
+ [result addObjectsFromArray:flatten(obj)];
128
+ #pragma clang diagnostic pop
129
+ } else {
130
+ [result addObject:obj];
131
+ }
132
+ }
133
+
134
+ // If the outmost call terminates, nil the reference to flatten to break
135
+ // the retain cycle
136
+ if (input == array) {
137
+ flatten = nil;
138
+ }
139
+
140
+ return result;
141
+ };
142
+
143
+ return [USArrayWrapper wrap:flatten(self.array)];
144
+ }
145
+
146
+ - (USArrayWrapper *(^)(NSArray *))without
147
+ {
148
+ return ^USArrayWrapper *(NSArray *value) {
149
+ return self.reject(^(id obj){
150
+ return [value containsObject:obj];
151
+ });
152
+ };
153
+ }
154
+
155
+ - (USArrayWrapper *)shuffle
156
+ {
157
+ NSMutableArray *result = [self.array mutableCopy];
158
+
159
+ for (NSInteger i = result.count - 1; i > 0; i--) {
160
+ [result exchangeObjectAtIndex:arc4random() % (i + 1)
161
+ withObjectAtIndex:i];
162
+ }
163
+
164
+ return [[USArrayWrapper alloc] initWithArray:result];
165
+ }
166
+
167
+ - (id (^)(id, UnderscoreReduceBlock))reduce
168
+ {
169
+ return ^USArrayWrapper *(id memo, UnderscoreReduceBlock function) {
170
+ for (id obj in self.array) {
171
+ memo = function(memo, obj);
172
+ }
173
+
174
+ return memo;
175
+ };
176
+ }
177
+
178
+ - (id (^)(id, UnderscoreReduceBlock))reduceRight
179
+ {
180
+ return ^USArrayWrapper *(id memo, UnderscoreReduceBlock function) {
181
+ for (id obj in self.array.reverseObjectEnumerator) {
182
+ memo = function(memo, obj);
183
+ }
184
+
185
+ return memo;
186
+ };
187
+ }
188
+
189
+ - (USArrayWrapper *(^)(UnderscoreArrayIteratorBlock))each
190
+ {
191
+ return ^USArrayWrapper *(UnderscoreArrayIteratorBlock block) {
192
+ for (id obj in self.array) {
193
+ block(obj);
194
+ }
195
+
196
+ return self;
197
+ };
198
+ }
199
+
200
+ - (USArrayWrapper *(^)(UnderscoreArrayMapBlock))map
201
+ {
202
+ return ^USArrayWrapper *(UnderscoreArrayMapBlock block) {
203
+ NSMutableArray *result = [NSMutableArray arrayWithCapacity:self.array.count];
204
+
205
+ for (id obj in self.array) {
206
+ id mapped = block(obj);
207
+
208
+ if (mapped) {
209
+ [result addObject:mapped];
210
+ }
211
+ }
212
+
213
+ return [[USArrayWrapper alloc] initWithArray:result];
214
+ };
215
+ }
216
+
217
+ - (USArrayWrapper *(^)(NSString *))pluck
218
+ {
219
+ return ^USArrayWrapper *(NSString *keyPath) {
220
+ return self.map(^id (id obj) {
221
+ return [obj valueForKeyPath:keyPath];
222
+ });
223
+ };
224
+ }
225
+
226
+ - (USArrayWrapper *)uniq
227
+ {
228
+ NSSet* uniqSet = [NSSet setWithArray:self.array];
229
+ NSArray* result = [uniqSet allObjects];
230
+
231
+ return [[USArrayWrapper alloc] initWithArray:result];
232
+ }
233
+
234
+ - (id (^)(UnderscoreTestBlock))find
235
+ {
236
+ return ^id (UnderscoreTestBlock test) {
237
+ for (id obj in self.array) {
238
+ if (test(obj)) {
239
+ return obj;
240
+ }
241
+ }
242
+
243
+ return nil;
244
+ };
245
+ }
246
+
247
+ - (USArrayWrapper *(^)(UnderscoreTestBlock))filter
248
+ {
249
+ return ^USArrayWrapper *(UnderscoreTestBlock test) {
250
+ return self.map(^id (id obj) {
251
+ return test(obj) ? obj : nil;
252
+ });
253
+ };
254
+ }
255
+
256
+ - (USArrayWrapper *(^)(UnderscoreTestBlock))reject
257
+ {
258
+ return ^USArrayWrapper *(UnderscoreTestBlock test) {
259
+ return self.filter(Underscore.negate(test));
260
+ };
261
+ }
262
+
263
+ - (BOOL (^)(UnderscoreTestBlock))all
264
+ {
265
+ return ^BOOL (UnderscoreTestBlock test) {
266
+ if (self.array.count == 0) {
267
+ return NO;
268
+ }
269
+
270
+ BOOL result = YES;
271
+
272
+ for (id obj in self.array) {
273
+ if (!test(obj)) {
274
+ return NO;
275
+ }
276
+ }
277
+
278
+ return result;
279
+ };
280
+ }
281
+
282
+ - (BOOL (^)(UnderscoreTestBlock))any
283
+ {
284
+ return ^BOOL (UnderscoreTestBlock test) {
285
+ BOOL result = NO;
286
+
287
+ for (id obj in self.array) {
288
+ if (test(obj)) {
289
+ return YES;
290
+ }
291
+ }
292
+
293
+ return result;
294
+ };
295
+ }
296
+
297
+ - (USArrayWrapper *(^)(UnderscoreSortBlock))sort
298
+ {
299
+ return ^USArrayWrapper *(UnderscoreSortBlock block) {
300
+ NSArray *result = [self.array sortedArrayUsingComparator:block];
301
+ return [[USArrayWrapper alloc] initWithArray:result];
302
+ };
303
+ }
304
+
305
+ @end