Permalink
Browse files

Code is now portable between ARC and non-ARC projects without compile…

…r flags needing to be placed on the classes
  • Loading branch information...
1 parent 6dd1e2c commit 09a73ff81de05fea516f531ff005f12b984735e7 Mitch Clay committed Nov 15, 2012
View
@@ -146,7 +146,11 @@ struct DTOutset {
@abstract The object that acts as the data source of the receiving grid view.
@discussion The data source must adopt the DTGridViewDataSource protocol. The data source is not retained.
*/
+#if __has_feature(objc_arc)
+@property (nonatomic, retain) IBOutlet NSObject<DTGridViewDataSource> *dataSource;
+#else
@property (nonatomic, assign) IBOutlet NSObject<DTGridViewDataSource> *dataSource;
+#endif
/*!
@abstract The object that acts as the delegate of the receiving grid view.
View
@@ -53,13 +53,16 @@ @implementation DTGridView
- (void)dealloc {
super.delegate = nil;
self.dataSource = nil;
+#if __has_feature(objc_arc)
+#else
[cellsOnScreen release], cellsOnScreen = nil;
[gridRows release], gridRows = nil;
[rowPositions release], rowPositions = nil;
[rowHeights release], rowHeights = nil;
[freeCells release], freeCells = nil;
[cellInfoForCellsOnScreen release], cellInfoForCellsOnScreen = nil;
[super dealloc];
+#endif
}
- (void)setGridDelegate:(id <DTGridViewDelegate>)aDelegate {
@@ -202,8 +205,11 @@ - (void)addCellWithInfo:(NSObject<DTGridViewCellInfoProtocol> *)info {
[cellInfoForCellsOnScreen addObject:info];
[cellInfoForCellsOnScreen sortUsingFunction:intSort context:NULL];
-
+#if __has_feature(objc_arc)
+ DTGridViewCell *cell = [self findViewForRow:info.yPosition column:info.xPosition];
+#else
DTGridViewCell *cell = [[self findViewForRow:info.yPosition column:info.xPosition] retain];
+#endif
[cell setNeedsDisplay];
cell.xPosition = info.xPosition;
cell.yPosition = info.yPosition;
@@ -230,8 +236,10 @@ - (void)addCellWithInfo:(NSObject<DTGridViewCellInfoProtocol> *)info {
break;
}
}
-
+#if __has_feature(objc_arc)
+#else
[cell release];
+#endif
}
@@ -248,9 +256,10 @@ - (void)removeCellWithInfo:(DTGridViewCellInfo *)info {
DTGridViewCell *cell = [row objectAtIndex:info.xPosition];
if (![cell isKindOfClass:[DTGridViewCell class]]) return;
-
+#if __has_feature(objc_arc)
+#else
[cell retain];
-
+#endif
[cell removeFromSuperview];
[row replaceObjectAtIndex:info.xPosition withObject:info];
@@ -261,8 +270,10 @@ - (void)removeCellWithInfo:(DTGridViewCellInfo *)info {
//cell.frame = CGRectZero;
[freeCells addObject:cell];
-
+#if __has_feature(objc_arc)
+#else
[cell release];
+#endif
}
- (CGRect)visibleRect {
@@ -408,19 +419,27 @@ - (void)loadData {
info.frame = CGRectMake(x,y,width,height);
[cellInfoArrayCols addObject:info];
-
+#if __has_feature(objc_arc)
+#else
[info release];
+#endif
}
[cellInfoArrayRows addObject:cellInfoArrayCols];
+#if __has_feature(objc_arc)
+#else
[cellInfoArrayCols release];
+#endif
}
self.contentSize = CGSizeMake(maxWidth, maxHeight);
self.gridCells = cellInfoArrayRows;
+#if __has_feature(objc_arc)
+#else
[cellInfoArrayRows release];
+#endif
if ([self.subviews count] > [self.gridCells count]) {
// the underlying data must have reduced, time to iterate
@@ -436,8 +455,10 @@ - (void)loadData {
[cell removeFromSuperview];
}
}
-
+#if __has_feature(objc_arc)
+#else
[subviewsCopy release];
+#endif
}
}
@@ -517,9 +538,11 @@ - (void)checkViews {
else if (isGoingDown)
[self checkNewRowStartingWithCellInfo:[orderedCells lastObject] goingUp:NO];
-
+#if __has_feature(objc_arc)
+#else
[leftRightCells release];
[orderedCells release];
+#endif
}
- (void)initialiseViews {
@@ -635,10 +658,20 @@ - (DTGridViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier {
for (DTGridViewCell *c in freeCells) {
if ([c.identifier isEqualToString:identifier]) {
+#if __has_feature(objc_arc)
+ id cell = c;
+#else
[c retain];
+#endif
[freeCells removeObject:c];
- [c prepareForReuse];
+
+#if __has_feature(objc_arc)
+ [cell prepareForReuse];
+ return cell;
+#else
+ [c prepareForReuse];
return [c autorelease];
+#endif
}
}
View
@@ -27,7 +27,11 @@
id<DTGridViewCellDelegate> delegate;
}
+#if __has_feature(objc_arc)
+@property (nonatomic, retain) id delegate;
+#else
@property (nonatomic, assign) id delegate;
+#endif
@property (nonatomic, copy) NSString *identifier;
@property (nonatomic, assign) BOOL selected;
@property (nonatomic, assign) BOOL highlighted;
View
@@ -33,10 +33,13 @@ - (id)initWithReuseIdentifier:(NSString *)anIdentifier {
return self;
}
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[identifier release];
[super dealloc];
}
+#endif
- (void)awakeFromNib {
identifier = nil;
View
@@ -26,11 +26,14 @@ - (void)viewDidUnload {
self.gridView = nil;
}
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[gridView release];
gridView = nil;
[super dealloc];
}
+#endif
- (NSInteger)numberOfRowsInGridView:(DTGridView *)gridView {
return 0;
@@ -57,11 +57,14 @@ - (void)drawRect:(CGRect)rect {
[self layoutSubviews];
}
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[titleLabel release];
[subtitleLabel release];
[super dealloc];
}
+#endif
- (NSString *)description {
return [NSString stringWithFormat:@"<%@ title:%@ frame=(%i %i; %i %i)>", [self class], self.titleLabel.text, (NSInteger)self.frame.origin.x, (NSInteger)self.frame.origin.y, (NSInteger)self.frame.size.width, (NSInteger)self.frame.size.height];
@@ -14,11 +14,14 @@ @interface DTSnapGridView ()
@implementation DTSnapGridView
@dynamic delegate;
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[decelerationTimer release];
decelerationTimer = nil;
[super dealloc];
}
+#endif
- (void)layoutSubviews {
[super layoutSubviews];

0 comments on commit 09a73ff

Please sign in to comment.