Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ARC

  • Loading branch information...
commit f15843b8b93f607577722331ba0e857c48dae819 1 parent 6db3a09
@mxcl authored
View
7 MBActionSheet.m
@@ -6,12 +6,7 @@ @implementation MBActionSheet
+ (id)actionSheet {
MBActionSheet *sheet = [MBActionSheet new];
sheet.delegate = sheet;
- return [sheet autorelease];
-}
-
-- (void)dealloc {
- [completionBlock release];
- [super dealloc];
+ return sheet
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
View
15 NSArray+mxcl.h
@@ -1,19 +1,23 @@
#import <Foundation/Foundation.h>
@interface NSArray (RubyEnumerable)
-- (id)map:(id (^)(id o))block;
-- (id)select:(BOOL (^)(id o))block;
+- (NSArray *)map:(id (^)(id o))block;
+- (NSArray *)select:(BOOL (^)(id o))block;
+- (NSArray *)reject:(BOOL (^)(id o))block;
- (id)find:(BOOL (^)(id o))block;
-- (id)flatten;
+- (NSArray *)flatten;
+
+- (id)inject:(id (^)(id memo, id obj))block;
+- (id)inject:(id)initialMemo block:(id (^)(id memo, id obj))block;
+
@end
@interface NSArray (mxcl)
-- (id)sortedArrayUsingDescriptor:(NSSortDescriptor *)descriptor;
- (id)firstObject;
// Do not use this if there a chance that all values are equal
// or if most of the values are equal.
-- (id)shuffledArray;
+- (NSArray *)shuffledArray;
- (NSData *)JSONData;
- (NSString *)JSONString;
@@ -24,6 +28,5 @@
@end
@interface NSMutableArray (mxcl)
-- (void)sortUsingDescriptor:(NSSortDescriptor *)descriptor;
- (id)pop;
@end
View
25 NSArray+mxcl.m
@@ -3,6 +3,16 @@
@implementation NSArray (RubyEnumerable)
+- (id)inject:(id (^)(id memo, id obj))block {
+ return [self inject:nil block:block];
+}
+
+- (id)inject:(id)memo block:(id (^)(id memo, id obj))block {
+ for (id obj in self)
+ memo = block(memo, obj);
+ return memo;
+}
+
- (NSArray *)map:(id (^)(id obj))block {
id objs[self.count];
int ii = 0;
@@ -24,6 +34,12 @@ - (id)select:(BOOL (^)(id o))block {
return [NSArray arrayWithObjects:objs count:ii];
}
+- (id)reject:(BOOL (^)(id o))block {
+ return [self select:^BOOL(id o) {
+ return !block(o);
+ }];
+}
+
- (id)find:(BOOL (^)(id o))block {
for (id item in self)
if (block(item))
@@ -46,9 +62,6 @@ - (id)flatten {
@implementation NSArray (mxcl)
-- (id)sortedArrayUsingDescriptor:(NSSortDescriptor *)descriptor {
- return [self sortedArrayUsingDescriptors:@[descriptor]];
-}
- (id)firstObject {
return self.count > 0
? self[0]
@@ -89,13 +102,9 @@ - (id)uniq {
@implementation NSMutableArray (mxcl)
-- (void)sortUsingDescriptor:(NSSortDescriptor *)descriptor {
- [self sortUsingDescriptors:@[descriptor]];
-}
-
- (id)pop {
if (self.count) {
- id o = [[self[0] retain] autorelease];
+ id o = self[0];
[self removeObjectAtIndex:0];
return o;
} else {
View
4 NSNumber+mxcl.m
@@ -4,8 +4,6 @@ @implementation NSNumber (mxcl)
- (NSString *)localizedString {
NSNumberFormatter *nf = [NSNumberFormatter new];
[nf setNumberStyle: NSNumberFormatterDecimalStyle];
- NSString *s = [nf stringFromNumber:self];
- [nf release];
- return s;
+ return [nf stringFromNumber:self];
}
@end
View
10 NSThread+mxcl.m
@@ -1,6 +1,8 @@
#import "NSThread+mxcl.h"
+
@implementation NSThread (BlocksAdditions)
+
- (void)performBlock:(void (^)())block
{
if ([[NSThread currentThread] isEqual:self])
@@ -8,20 +10,24 @@ - (void)performBlock:(void (^)())block
else
[self performBlock:block waitUntilDone:NO];
}
+
- (void)performBlock:(void (^)())block waitUntilDone:(BOOL)wait
{
[NSThread performSelector:@selector(ng_runBlock:)
onThread:self
- withObject:[[block copy] autorelease]
+ withObject:[block copy]
waitUntilDone:wait];
}
+
+ (void)ng_runBlock:(void (^)())block
{
block();
}
+
+ (void)performBlockInBackground:(void (^)())block
{
[NSThread performSelectorInBackground:@selector(ng_runBlock:)
- withObject:[[block copy] autorelease]];
+ withObject:[block copy]];
}
+
@end
View
8 NSURLConnection+mxcl.m
@@ -18,12 +18,6 @@ - (id)initWithRequest:(id)rq {
}
return self;
}
-- (void)dealloc {
- [data release];
- [badblock release];
- [block200 release];
- [super dealloc];
-}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (rc == 200) {
block200(data);
@@ -48,6 +42,6 @@ + (id)connectionWithRequest:(id)rq twohundred:(void (^)(NSData *))block200 epicf
MBURLConnection *conn = [[MBURLConnection alloc] initWithRequest:rq];
conn.badblock = badblock;
conn.block200 = block200;
- return [conn autorelease];
+ return conn;
}
@end
View
1  UIAlertView+mxcl.m
@@ -15,7 +15,6 @@ + (void)showAlertViewForError:(NSError *)error title:(NSString *)title
cancelButtonTitle:@"That Sucks!"
otherButtonTitles:nil];
[alertView show];
- [alertView release];
}
}
@end
View
2  UITableView+mxcl.m
@@ -8,7 +8,7 @@ - (UITableViewCell *)dequeueReusableCell {
- (UITableViewCell *)dequeueReusableCellWithStyle:(UITableViewCellStyle)style {
#define CELLID @"mxcl_UITableViewCellID"
return [self dequeueReusableCellWithIdentifier:CELLID]
- ?: [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:CELLID] autorelease];
+ ?: [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:CELLID];
#undef CELLID
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.