Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #81 from aufflick/master

Arc migration
  • Loading branch information...
commit 4072978f4a573060b09e8687feb6f1874ef2ce29 2 parents 90ab0f3 + 12b747d
Jim Dovey authored
4 AQGridView.xcodeproj/project.pbxproj
View
@@ -281,6 +281,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/AQGridView.dst;
GCC_DYNAMIC_NO_PIC = NO;
@@ -292,6 +293,7 @@
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = BUILTIN_IMAGES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/local/lib;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = AQGridView;
};
name = Debug;
@@ -301,6 +303,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
DSTROOT = /tmp/AQGridView.dst;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -308,6 +311,7 @@
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = BUILTIN_IMAGES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/local/lib;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = AQGridView;
};
name = Release;
2  Classes/AQGridView.h
View
@@ -97,7 +97,7 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
@interface AQGridView : UIScrollView
{
- id<AQGridViewDataSource> _dataSource;
+ id<AQGridViewDataSource> __unsafe_unretained _dataSource;
AQGridViewData * _gridData;
NSMutableArray * _updateInfoStack;
551 Classes/AQGridView.m
View
@@ -152,21 +152,6 @@ - (void)drawRect:(CGRect)rect {
}
*/
-- (void)dealloc
-{
- [_visibleCells release];
- [_reusableGridCells release];
- [_highlightedIndices release];
- [_backgroundView release];
- [_separatorColor release];
- [_gridData release];
- [_updateInfoStack release];
- [_animatingCells release];
- [_headerView release];
- [_footerView release];
-
- [super dealloc];
-}
#pragma mark -
#pragma mark Properties
@@ -361,7 +346,7 @@ - (CGSize) gridCellSize
- (UIView *) gridHeaderView
{
- return ( [[_headerView retain] autorelease] );
+ return ( _headerView );
}
- (void) setGridHeaderView: (UIView *) newHeaderView
@@ -370,9 +355,8 @@ - (void) setGridHeaderView: (UIView *) newHeaderView
return;
[_headerView removeFromSuperview];
- [_headerView release];
- _headerView = [newHeaderView retain];
+ _headerView = newHeaderView;
if ( _headerView == nil )
{
_gridData.topPadding = 0.0;
@@ -388,7 +372,7 @@ - (void) setGridHeaderView: (UIView *) newHeaderView
- (UIView *) gridFooterView
{
- return ( [[_footerView retain] autorelease] );
+ return ( _footerView );
}
- (void) setGridFooterView: (UIView *) newFooterView
@@ -397,9 +381,8 @@ - (void) setGridFooterView: (UIView *) newFooterView
return;
[_footerView removeFromSuperview];
- [_footerView release];
- _footerView = [newFooterView retain];
+ _footerView = newFooterView;
if ( _footerView == nil )
{
_gridData.bottomPadding = 0.0;
@@ -425,8 +408,6 @@ - (void) setContentSizeGrowsToFillBounds: (BOOL) value
- (void) setAnimatingCells: (NSSet *) set
{
- [set retain];
- [_animatingCells release];
_animatingCells = set;
NSMutableIndexSet * indices = [[NSMutableIndexSet alloc] init];
@@ -437,7 +418,6 @@ - (void) setAnimatingCells: (NSSet *) set
}
self.animatingIndices = indices;
- [indices release];
}
- (BOOL) isAnimatingUpdates
@@ -596,14 +576,14 @@ - (void) setEditing: (BOOL) value
- (AQGridViewCell *) dequeueReusableCellWithIdentifier: (NSString *) reuseIdentifier
{
NSMutableSet * cells = [_reusableGridCells objectForKey: reuseIdentifier];
- AQGridViewCell * cell = [[cells anyObject] retain];
+ AQGridViewCell * cell = [cells anyObject];
if ( cell == nil )
return ( nil );
[cell prepareForReuse];
[cells removeObject: cell];
- return ( [cell autorelease] );
+ return ( cell );
}
- (void) enqueueReusableCells: (NSArray *) reusableCells
@@ -615,7 +595,6 @@ - (void) enqueueReusableCells: (NSArray *) reusableCells
{
reuseSet = [[NSMutableSet alloc] initWithCapacity: 32];
[_reusableGridCells setObject: reuseSet forKey: cell.reuseIdentifier];
- [reuseSet release];
}
else if ( [reuseSet member: cell] == cell )
{
@@ -677,9 +656,7 @@ - (void) layoutSubviews
if ( (_reloadingSuspendedCount == 0) && (!CGRectIsEmpty([self gridViewVisibleBounds])) )
{
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- [self updateVisibleGridCellsNow];
- [pool release];
+ [self updateVisibleGridCellsNow];
}
if ( _flags.allCellsNeedLayout == 1 )
@@ -787,7 +764,7 @@ - (AQGridViewCell *) cellForItemAtPoint: (CGPoint) point
- (NSArray *) visibleCells
{
- return ( [[_visibleCells copy] autorelease] );
+ return ( [_visibleCells copy] );
}
- (NSIndexSet *) visibleCellIndices
@@ -901,7 +878,6 @@ - (void) fixCellsFromAnimation
[_visibleCells removeObjectsInArray: newVisibleCells];
[_visibleCells makeObjectsPerformSelector: @selector(removeFromSuperview)];
[_visibleCells setArray: newVisibleCells];
- [newVisibleCells release];
self.animatingCells = nil;
NSMutableSet * removals = [[NSMutableSet alloc] init];
@@ -915,7 +891,6 @@ - (void) fixCellsFromAnimation
}
[removals makeObjectsPerformSelector: @selector(removeFromSuperview)];
- [removals release];
// update the content size/offset based on the new grid data
CGPoint oldMaxLocation = CGPointMake(CGRectGetMaxX(self.bounds), CGRectGetMaxY(self.bounds));
@@ -928,7 +903,6 @@ - (void) setupUpdateAnimations
AQGridViewUpdateInfo * info = [[AQGridViewUpdateInfo alloc] initWithOldGridData: _gridData forGridView: self];
[_updateInfoStack addObject: info];
- [info release];
}
- (void) endUpdateAnimations
@@ -960,13 +934,12 @@ - (void) endUpdateAnimations
// there's a race condition with the info's removal from the stack if there are no animations taking place,
// where -cellUpdateAnimationStopped:finished:context: is called immediately, before we've finished with the
// object. Therefore we retain it while we want to use it, just in case
- [info retain];
[info cleanupUpdateItems];
_animationCount++;
//NSAssert(_animationCount == 1, @"Stacked animations occurring!!");
- [UIView beginAnimations: @"CellUpdates" context: info];
+ [UIView beginAnimations: @"CellUpdates" context: (void*)objc_unretainedPointer(info)];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(cellUpdateAnimationStopped:finished:context:)];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
@@ -975,19 +948,17 @@ - (void) endUpdateAnimations
self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];
- [_gridData release];
- _gridData = [[info newGridViewData] retain];
+ _gridData = [info newGridViewData];
if ( _selectedIndex != NSNotFound )
_selectedIndex = [info newIndexForOldIndex: _selectedIndex];
- [info release];
_reloadingSuspendedCount--;
[UIView commitAnimations];
}
- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context
{
- AQGridViewUpdateInfo * info = (AQGridViewUpdateInfo *)context;
+ AQGridViewUpdateInfo * info = (__bridge AQGridViewUpdateInfo *)context;
// if nothing was animated, we don't have to do anything at all
// if ( self.animatingCells.count != 0 )
@@ -1202,7 +1173,7 @@ - (void) deselectItemAtIndex: (NSUInteger) index animated: (BOOL) animated
- (UIView *) backgroundView
{
- return ( [[_backgroundView retain] autorelease] );
+ return ( _backgroundView );
}
- (void) setBackgroundView: (UIView *) newView
@@ -1211,9 +1182,8 @@ - (void) setBackgroundView: (UIView *) newView
return;
[_backgroundView removeFromSuperview];
- [_backgroundView release];
- _backgroundView = [newView retain];
+ _backgroundView = newView;
_backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
CGRect frame = self.bounds;
frame.size = self.contentSize;
@@ -1238,7 +1208,7 @@ - (void) setBackgroundView: (UIView *) newView
- (UIColor *) separatorColor
{
- return ( [[_separatorColor retain] autorelease] );
+ return ( _separatorColor );
}
- (void) setSeparatorColor: (UIColor *) color
@@ -1246,8 +1216,6 @@ - (void) setSeparatorColor: (UIColor *) color
if ( color == _separatorColor )
return;
- [color retain];
- [_separatorColor release];
_separatorColor = color;
for ( AQGridViewCell * cell in _visibleCells )
@@ -1289,7 +1257,7 @@ - (BOOL) _canSelectItemContainingHitView: (UIView *) hitView
CGPoint hitCenter = [self convertPoint:[hitView center] fromView:hitView];
- for ( AQGridViewCell *aCell in [[[self visibleCells] copy] autorelease])
+ for ( AQGridViewCell *aCell in [[self visibleCells] copy])
{
if ( CGRectContainsPoint( aCell.frame, hitCenter ) )
@@ -1367,7 +1335,7 @@ - (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
CGPoint pt = [touch locationInView: self];
UIView * hitView = [self _basicHitTest: pt withEvent: event];
- _touchedContentView = [hitView retain];
+ _touchedContentView = hitView;
// unhighlight anything not here
if ( hitView != self )
@@ -1418,7 +1386,6 @@ - (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
//[self _cancelContentTouchUsingEvent: event forced: NO];
[self highlightItemAtIndex: NSNotFound animated: NO scrollPosition: AQGridViewScrollPositionNone];
_flags.ignoreTouchSelect = 1;
- [_touchedContentView release];
_touchedContentView = nil;
}
@@ -1438,13 +1405,11 @@ - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
[super touchesEnded: touches withEvent: event];
if ( _touchedContentView != nil )
{
- [hitView release];
- hitView = [_touchedContentView retain];
+ hitView = _touchedContentView;
}
if ( [hitView superview] == nil )
{
- [hitView release];
hitView = nil;
}
@@ -1471,14 +1436,13 @@ - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
NSSet *touchEventSet = [event allTouches];
// run this on the next runloop tick
- UserSelectItemIndexParams* selectorParams = [[[UserSelectItemIndexParams alloc] init] autorelease];
+ UserSelectItemIndexParams* selectorParams = [[UserSelectItemIndexParams alloc] init];
selectorParams.indexNum = _pendingSelectionIndex;
selectorParams.numFingers = [touchEventSet count];
[self performSelector: @selector(_userSelectItemAtIndex:)
withObject: selectorParams
afterDelay:0.0];
- [hitView release];
} while (0);
@@ -1493,7 +1457,6 @@ - (void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event
[self highlightItemAtIndex: NSNotFound animated: NO scrollPosition: AQGridViewScrollPositionNone];
[super touchesCancelled: touches withEvent: event];
- [_touchedContentView release];
_touchedContentView = nil;
}
@@ -1529,15 +1492,14 @@ - (NSUInteger) visibleCellListIndexForItemIndex: (NSUInteger) itemIndex
@implementation AQGridView (AQCellLayout)
+NSArray * __sortDescriptors;
+
- (void) sortVisibleCellList
{
- static NSArray * __sortDescriptors = nil;
- if ( __sortDescriptors == nil )
- {
- NSArray * obj = [[NSArray alloc] initWithObjects: [[[NSSortDescriptor alloc] initWithKey: @"displayIndex" ascending: YES] autorelease], nil];
- if ( OSAtomicCompareAndSwapPtrBarrier(nil, obj, (void * volatile *)&__sortDescriptors) == false )
- [obj release]; // already stored by another thread
- }
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ __sortDescriptors = [[NSArray alloc] initWithObjects: [[NSSortDescriptor alloc] initWithKey: @"displayIndex" ascending: YES], nil];
+ });
[_visibleCells sortUsingDescriptors: __sortDescriptors];
}
@@ -1555,231 +1517,226 @@ - (void) updateVisibleGridCellsNow
_reloadingSuspendedCount++;
-
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- NSIndexSet * newVisibleIndices = [_gridData indicesOfCellsInRect: [self gridViewVisibleBounds]];
-
- BOOL enableAnim = [UIView areAnimationsEnabled];
- [UIView setAnimationsEnabled: NO];
-
- @try
- {
- // a couple of simple tests
- // TODO: if we replace _visibleIndices with an index set, this comparison will have to change
- if ( ([_visibleCells count] != [newVisibleIndices count]) ||
- ([newVisibleIndices countOfIndexesInRange: _visibleIndices] != _visibleIndices.length) )
- {
- // something has changed. Compute intersections and remove/add cells as required
- NSIndexSet * currentVisibleIndices = [NSIndexSet indexSetWithIndexesInRange: _visibleIndices];
-
- // index sets for removed and inserted items
- NSMutableIndexSet * removedIndices = nil, * insertedIndices = nil;
-
- // handle the simple case first
- // TODO: if we replace _visibleIndices with an index set, this comparison will have to change
- if ( [currentVisibleIndices intersectsIndexesInRange: _visibleIndices] == NO )
- {
- removedIndices = [[currentVisibleIndices mutableCopy] autorelease];
- insertedIndices = [[newVisibleIndices mutableCopy] autorelease];
- }
- else // more complicated -- compute negative intersections
- {
- removedIndices = [[[currentVisibleIndices aq_indexesOutsideIndexSet: newVisibleIndices] mutableCopy] autorelease];
- insertedIndices = [[[newVisibleIndices aq_indexesOutsideIndexSet: currentVisibleIndices] mutableCopy] autorelease];
- }
-
- if ( [removedIndices count] != 0 )
- {
- NSMutableIndexSet * shifted = [removedIndices mutableCopy];
-
- // get an index set for everything being removed relative to items' locations within the visible cell list
- [shifted shiftIndexesStartingAtIndex: [removedIndices firstIndex] by: 0 - (NSInteger)_visibleIndices.location];
- //NSLog( @"Removed indices relative to visible cell list: %@", shifted );
-
- NSUInteger index=[shifted firstIndex];
- while(index != NSNotFound){
- //NSLog(@"%i >= %i ?", index, [_visibleCells count]);
- if (index >= [_visibleCells count]) {
- [shifted removeIndex:index];
- }
- index=[shifted indexGreaterThanIndex: index];
- }
-
- // pull out the cells for manipulation
- NSMutableArray * removedCells = [[_visibleCells objectsAtIndexes: shifted] mutableCopy];
-
- // remove them from the visible list
- [_visibleCells removeObjectsInArray: removedCells];
- //NSLog( @"After removals, visible cells count = %lu", (unsigned long)[_visibleCells count] );
-
- // don't need this any more
- [shifted release]; shifted = nil;
-
- // remove cells from the view hierarchy -- but only if they're not being animated by something else
- NSArray * animating = [[self.animatingCells valueForKey: @"animatingView"] allObjects];
- if ( animating != nil )
- [removedCells removeObjectsInArray: animating];
-
- // these are not being displayed or animated offscreen-- take them off the screen immediately
- [removedCells makeObjectsPerformSelector: @selector(removeFromSuperview)];
-
- // put them into the cell reuse queue
- [self enqueueReusableCells: removedCells];
-
- [removedCells release];
- }
-
- if ( [insertedIndices count] != 0 )
- {
- // some items are going in -- put them at the end and the sort function will move them to the right index during layout
- // if any of these new indices correspond to animating cells (NOT UIImageViews) then copy them into the visible cell list
- NSMutableIndexSet * animatingInserted = [insertedIndices mutableCopy];
-
- // compute the intersection of insertedIndices and _animatingIndices
- NSUInteger idx = [insertedIndices firstIndex];
- while ( idx != NSNotFound )
- {
- if ( [_animatingIndices containsIndex: idx] == NO )
- [animatingInserted removeIndex: idx];
-
- idx = [insertedIndices indexGreaterThanIndex: idx];
- }
-
- if ( [animatingInserted count] != 0 )
- {
- for ( AQGridViewAnimatorItem * item in _animatingCells )
- {
- if ( [newVisibleIndices containsIndex: item.index] == NO )
- continue;
-
- if ( [item.animatingView isKindOfClass: [AQGridViewCell class]] )
- {
- // ensure this is in the visible cell list
- if ( [_visibleCells containsObject: item.animatingView] == NO )
- //[_visibleCells addObject: item.animatingView];
- [self doAddVisibleCell: item.animatingView];
- }
- else
- {
- // it's an image that's being moved, likely because it *was* going offscreen before
- // the user scrolled. Create a real cell, but hide it until the animation is complete.
- AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
- //[_visibleCells addObject: cell];
- [self doAddVisibleCell: cell];
-
- // we don't tell the delegate yet, we just hide it
- cell.hiddenForAnimation = YES;
- }
- }
-
- // remove these from the set of indices for which we will generate new cells
- [insertedIndices removeIndexes: animatingInserted];
- }
-
- [animatingInserted release];
-
- // insert cells for these indices
- idx = [insertedIndices firstIndex];
- while ( idx != NSNotFound )
- {
- AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
- //[_visibleCells addObject: cell];
- [self doAddVisibleCell: cell];
-
- // tell the delegate
- [self delegateWillDisplayCell: cell atIndex: idx];
-
- idx = [insertedIndices indexGreaterThanIndex: idx];
- }
- }
-
- if ( [_visibleCells count] > [newVisibleIndices count] )
- {
- //NSLog( @"Have to prune visible cell list, I've still got extra cells in there!" );
- NSMutableIndexSet * animatingDestinationIndices = [[NSMutableIndexSet alloc] init];
- for ( AQGridViewAnimatorItem * item in _animatingCells )
+ @autoreleasepool {
+
+ NSIndexSet * newVisibleIndices = [_gridData indicesOfCellsInRect: [self gridViewVisibleBounds]];
+
+ BOOL enableAnim = [UIView areAnimationsEnabled];
+ [UIView setAnimationsEnabled: NO];
+
+ @try
+ {
+ // a couple of simple tests
+ // TODO: if we replace _visibleIndices with an index set, this comparison will have to change
+ if ( ([_visibleCells count] != [newVisibleIndices count]) ||
+ ([newVisibleIndices countOfIndexesInRange: _visibleIndices] != _visibleIndices.length) )
+ {
+ // something has changed. Compute intersections and remove/add cells as required
+ NSIndexSet * currentVisibleIndices = [NSIndexSet indexSetWithIndexesInRange: _visibleIndices];
+
+ // index sets for removed and inserted items
+ NSMutableIndexSet * removedIndices = nil, * insertedIndices = nil;
+
+ // handle the simple case first
+ // TODO: if we replace _visibleIndices with an index set, this comparison will have to change
+ if ( [currentVisibleIndices intersectsIndexesInRange: _visibleIndices] == NO )
{
- [animatingDestinationIndices addIndex: item.index];
+ removedIndices = [currentVisibleIndices mutableCopy];
+ insertedIndices = [newVisibleIndices mutableCopy];
}
-
- NSMutableIndexSet * toRemove = [[NSMutableIndexSet alloc] init];
- NSMutableIndexSet * seen = [[NSMutableIndexSet alloc] init];
- NSUInteger i, count = [_visibleCells count];
- for ( i = 0; i < count; i++ )
- {
- AQGridViewCell * cell = [_visibleCells objectAtIndex: i];
- if ( [newVisibleIndices containsIndex: cell.displayIndex] == NO &&
- [animatingDestinationIndices containsIndex: cell.displayIndex] == NO )
- {
- NSLog( @"Cell for index %lu is still in visible list, removing...", (unsigned long)cell.displayIndex );
- [cell removeFromSuperview];
- [toRemove addIndex: i];
- }
- else if ( [seen containsIndex: cell.displayIndex] )
- {
- NSLog( @"Multiple cells with index %lu found-- removing duplicate...", (unsigned long)cell.displayIndex );
- [cell removeFromSuperview];
- [toRemove addIndex: i];
- }
-
- [seen addIndex: cell.displayIndex];
- }
-
- // all removed from superview, just need to remove from the list now
- [_visibleCells removeObjectsAtIndexes: toRemove];
- [toRemove release];
- [seen release];
- }
-
- if ( [_visibleCells count] < [newVisibleIndices count] )
- {
- NSLog( @"Visible cell list is missing some items!" );
-
- NSMutableIndexSet * visibleSet = [[NSMutableIndexSet alloc] init];
- for ( AQGridViewCell * cell in _visibleCells )
- {
- [visibleSet addIndex: cell.displayIndex];
- }
-
- NSMutableIndexSet * missingSet = [newVisibleIndices mutableCopy];
- [missingSet removeIndexes: visibleSet];
- [visibleSet release];
-
- NSLog( @"Got %lu missing indices", (unsigned long)[missingSet count] );
-
- NSUInteger idx = [missingSet firstIndex];
- while ( idx != NSNotFound )
- {
- AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
- //[_visibleCells addObject: cell];
- [self doAddVisibleCell: cell];
-
- // tell the delegate
- [self delegateWillDisplayCell: cell atIndex: idx];
-
- idx = [missingSet indexGreaterThanIndex: idx];
- }
-
- [missingSet release];
- }
-
- // everything should match up now, so update the visible range
- _visibleIndices.location = [newVisibleIndices firstIndex];
- _visibleIndices.length = [newVisibleIndices count];
-
- // layout these cells -- this will also sort the visible cell list
- [self layoutAllCells];
- }
- }
- @catch (id exception)
- {
- }
- @finally
- {
- [UIView setAnimationsEnabled: enableAnim];
- [pool drain];
- _reloadingSuspendedCount--;
- }
+ else // more complicated -- compute negative intersections
+ {
+ removedIndices = [[currentVisibleIndices aq_indexesOutsideIndexSet: newVisibleIndices] mutableCopy];
+ insertedIndices = [[newVisibleIndices aq_indexesOutsideIndexSet: currentVisibleIndices] mutableCopy];
+ }
+
+ if ( [removedIndices count] != 0 )
+ {
+ NSMutableIndexSet * shifted = [removedIndices mutableCopy];
+
+ // get an index set for everything being removed relative to items' locations within the visible cell list
+ [shifted shiftIndexesStartingAtIndex: [removedIndices firstIndex] by: 0 - (NSInteger)_visibleIndices.location];
+ //NSLog( @"Removed indices relative to visible cell list: %@", shifted );
+
+ NSUInteger index=[shifted firstIndex];
+ while(index != NSNotFound){
+ //NSLog(@"%i >= %i ?", index, [_visibleCells count]);
+ if (index >= [_visibleCells count]) {
+ [shifted removeIndex:index];
+ }
+ index=[shifted indexGreaterThanIndex: index];
+ }
+
+ // pull out the cells for manipulation
+ NSMutableArray * removedCells = [[_visibleCells objectsAtIndexes: shifted] mutableCopy];
+
+ // remove them from the visible list
+ [_visibleCells removeObjectsInArray: removedCells];
+ //NSLog( @"After removals, visible cells count = %lu", (unsigned long)[_visibleCells count] );
+
+ // don't need this any more
+ shifted = nil;
+
+ // remove cells from the view hierarchy -- but only if they're not being animated by something else
+ NSArray * animating = [[self.animatingCells valueForKey: @"animatingView"] allObjects];
+ if ( animating != nil )
+ [removedCells removeObjectsInArray: animating];
+
+ // these are not being displayed or animated offscreen-- take them off the screen immediately
+ [removedCells makeObjectsPerformSelector: @selector(removeFromSuperview)];
+
+ // put them into the cell reuse queue
+ [self enqueueReusableCells: removedCells];
+
+ }
+
+ if ( [insertedIndices count] != 0 )
+ {
+ // some items are going in -- put them at the end and the sort function will move them to the right index during layout
+ // if any of these new indices correspond to animating cells (NOT UIImageViews) then copy them into the visible cell list
+ NSMutableIndexSet * animatingInserted = [insertedIndices mutableCopy];
+
+ // compute the intersection of insertedIndices and _animatingIndices
+ NSUInteger idx = [insertedIndices firstIndex];
+ while ( idx != NSNotFound )
+ {
+ if ( [_animatingIndices containsIndex: idx] == NO )
+ [animatingInserted removeIndex: idx];
+
+ idx = [insertedIndices indexGreaterThanIndex: idx];
+ }
+
+ if ( [animatingInserted count] != 0 )
+ {
+ for ( AQGridViewAnimatorItem * item in _animatingCells )
+ {
+ if ( [newVisibleIndices containsIndex: item.index] == NO )
+ continue;
+
+ if ( [item.animatingView isKindOfClass: [AQGridViewCell class]] )
+ {
+ // ensure this is in the visible cell list
+ if ( [_visibleCells containsObject: item.animatingView] == NO )
+ //[_visibleCells addObject: item.animatingView];
+ [self doAddVisibleCell: item.animatingView];
+ }
+ else
+ {
+ // it's an image that's being moved, likely because it *was* going offscreen before
+ // the user scrolled. Create a real cell, but hide it until the animation is complete.
+ AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
+ //[_visibleCells addObject: cell];
+ [self doAddVisibleCell: cell];
+
+ // we don't tell the delegate yet, we just hide it
+ cell.hiddenForAnimation = YES;
+ }
+ }
+
+ // remove these from the set of indices for which we will generate new cells
+ [insertedIndices removeIndexes: animatingInserted];
+ }
+
+
+ // insert cells for these indices
+ idx = [insertedIndices firstIndex];
+ while ( idx != NSNotFound )
+ {
+ AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
+ //[_visibleCells addObject: cell];
+ [self doAddVisibleCell: cell];
+
+ // tell the delegate
+ [self delegateWillDisplayCell: cell atIndex: idx];
+
+ idx = [insertedIndices indexGreaterThanIndex: idx];
+ }
+ }
+
+ if ( [_visibleCells count] > [newVisibleIndices count] )
+ {
+ //NSLog( @"Have to prune visible cell list, I've still got extra cells in there!" );
+ NSMutableIndexSet * animatingDestinationIndices = [[NSMutableIndexSet alloc] init];
+ for ( AQGridViewAnimatorItem * item in _animatingCells )
+ {
+ [animatingDestinationIndices addIndex: item.index];
+ }
+
+ NSMutableIndexSet * toRemove = [[NSMutableIndexSet alloc] init];
+ NSMutableIndexSet * seen = [[NSMutableIndexSet alloc] init];
+ NSUInteger i, count = [_visibleCells count];
+ for ( i = 0; i < count; i++ )
+ {
+ AQGridViewCell * cell = [_visibleCells objectAtIndex: i];
+ if ( [newVisibleIndices containsIndex: cell.displayIndex] == NO &&
+ [animatingDestinationIndices containsIndex: cell.displayIndex] == NO )
+ {
+ NSLog( @"Cell for index %lu is still in visible list, removing...", (unsigned long)cell.displayIndex );
+ [cell removeFromSuperview];
+ [toRemove addIndex: i];
+ }
+ else if ( [seen containsIndex: cell.displayIndex] )
+ {
+ NSLog( @"Multiple cells with index %lu found-- removing duplicate...", (unsigned long)cell.displayIndex );
+ [cell removeFromSuperview];
+ [toRemove addIndex: i];
+ }
+
+ [seen addIndex: cell.displayIndex];
+ }
+
+ // all removed from superview, just need to remove from the list now
+ [_visibleCells removeObjectsAtIndexes: toRemove];
+ }
+
+ if ( [_visibleCells count] < [newVisibleIndices count] )
+ {
+ NSLog( @"Visible cell list is missing some items!" );
+
+ NSMutableIndexSet * visibleSet = [[NSMutableIndexSet alloc] init];
+ for ( AQGridViewCell * cell in _visibleCells )
+ {
+ [visibleSet addIndex: cell.displayIndex];
+ }
+
+ NSMutableIndexSet * missingSet = [newVisibleIndices mutableCopy];
+ [missingSet removeIndexes: visibleSet];
+
+ NSLog( @"Got %lu missing indices", (unsigned long)[missingSet count] );
+
+ NSUInteger idx = [missingSet firstIndex];
+ while ( idx != NSNotFound )
+ {
+ AQGridViewCell * cell = [self createPreparedCellForIndex: idx];
+ //[_visibleCells addObject: cell];
+ [self doAddVisibleCell: cell];
+
+ // tell the delegate
+ [self delegateWillDisplayCell: cell atIndex: idx];
+
+ idx = [missingSet indexGreaterThanIndex: idx];
+ }
+
+ }
+
+ // everything should match up now, so update the visible range
+ _visibleIndices.location = [newVisibleIndices firstIndex];
+ _visibleIndices.length = [newVisibleIndices count];
+
+ // layout these cells -- this will also sort the visible cell list
+ [self layoutAllCells];
+ }
+ }
+ @catch (id exception)
+ {
+ }
+ @finally
+ {
+ [UIView setAnimationsEnabled: enableAnim];
+ _reloadingSuspendedCount--;
+ }
+
+ }
}
/*
- (void) updateVisibleGridCellsNow
@@ -2100,22 +2057,22 @@ - (void) layoutCellsInVisibleCellRange: (NSRange) range
{
NSParameterAssert(range.location + range.length <= [_visibleCells count]);
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ @autoreleasepool {
- NSArray * layoutList = [_visibleCells subarrayWithRange: range];
- for ( AQGridViewCell * cell in layoutList )
- {
- if ( [_animatingIndices containsIndex: cell.displayIndex] )
- continue; // don't adjust layout of something that is animating around
+ NSArray * layoutList = [_visibleCells subarrayWithRange: range];
+ for ( AQGridViewCell * cell in layoutList )
+ {
+ if ( [_animatingIndices containsIndex: cell.displayIndex] )
+ continue; // don't adjust layout of something that is animating around
- CGRect gridRect = [_gridData cellRectAtIndex: cell.displayIndex];
- CGRect cellFrame = cell.frame;
+ CGRect gridRect = [_gridData cellRectAtIndex: cell.displayIndex];
+ CGRect cellFrame = cell.frame;
- cell.frame = [self fixCellFrame: cellFrame forGridRect: gridRect];
- cell.selected = (cell.displayIndex == _selectedIndex);
- }
+ cell.frame = [self fixCellFrame: cellFrame forGridRect: gridRect];
+ cell.selected = (cell.displayIndex == _selectedIndex);
+ }
- [pool drain];
+ }
}
- (void) layoutAllCells
11 Classes/AQGridViewAnimatorItem.m
View
@@ -17,14 +17,9 @@ + (AQGridViewAnimatorItem *) itemWithView: (UIView *) aView index: (NSUInteger)
AQGridViewAnimatorItem * result = [[self alloc] init];
result.animatingView = aView;
result.index = anIndex;
- return ( [result autorelease] );
+ return ( result );
}
-- (void) dealloc
-{
- self.animatingView = nil;
- [super dealloc];
-}
- (NSUInteger) hash
{
@@ -43,9 +38,9 @@ - (NSComparisonResult) compare: (id) obj
{
if ( [obj isKindOfClass: [self class]] == NO )
{
- if ( (void *)self < (void *)obj )
+ if ( (void *)objc_unretainedPointer(self) < (void *)objc_unretainedPointer(obj) )
return ( NSOrderedAscending );
- if ( (void *)self > (void *)obj )
+ if ( (void *)objc_unretainedPointer(self) > (void *)objc_unretainedPointer(obj) )
return ( NSOrderedDescending );
return ( NSOrderedSame ); // how ??!?!?
}
40 Classes/AQGridViewCell.m
View
@@ -96,20 +96,8 @@ - (void) awakeFromNib
- (void) dealloc
{
- [_reuseIdentifier release];
- [_contentView release];
- [_backgroundView release];
- [_selectedBackgroundView release];
- [_selectedOverlayView release];
- [_backgroundColor release];
- [_separatorColor release];
- [_selectionGlowColor release];
- [_bottomSeparatorView release];
- [_rightSeparatorView release];
if ( _selectionColorInfo != NULL )
CFRelease( _selectionColorInfo );
- [_fadeTimer release];
- [super dealloc];
}
- (NSComparisonResult) compareOriginAgainstCell: (AQGridViewCell *) otherCell
@@ -208,11 +196,11 @@ - (void) makeSubviewsOfView: (UIView *) aView nonOpaqueWithBackgroundColor: (UIC
{
if ( view.opaque )
{
- NSMutableDictionary * info = (NSMutableDictionary *) CFDictionaryGetValue( _selectionColorInfo, view );
+ NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
if ( info == nil )
{
info = [NSMutableDictionary dictionaryWithCapacity: 2];
- CFDictionarySetValue( _selectionColorInfo, view, info );
+ CFDictionarySetValue( _selectionColorInfo, objc_unretainedPointer(view), objc_unretainedPointer(info) );
}
id value = view.backgroundColor;
@@ -232,7 +220,7 @@ - (void) makeSubviewsOfViewOpaqueAgain: (UIView *) aView
{
for ( UIView * view in aView.subviews )
{
- NSMutableDictionary * info = (NSMutableDictionary *) CFDictionaryGetValue( _selectionColorInfo, view );
+ NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
if ( info != nil )
{
id value = [info objectForKey: @"backgroundColor"];
@@ -257,11 +245,11 @@ - (void) highlightSubviewsOfView: (UIView *) aView
{
if ( [view respondsToSelector: @selector(setHighlighted:)] )
{
- NSMutableDictionary * info = (NSMutableDictionary *) CFDictionaryGetValue( _selectionColorInfo, view );
+ NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
if ( info == nil )
{
info = [NSMutableDictionary dictionaryWithCapacity: 2];
- CFDictionarySetValue( _selectionColorInfo, view, info );
+ CFDictionarySetValue( _selectionColorInfo, objc_unretainedPointer(view), objc_unretainedPointer(info) );
}
// don't overwrite any prior cache of a view's original highlighted state.
@@ -287,7 +275,7 @@ - (void) resetHighlightForSubviewsOfView: (UIView *) aView
for ( UIView * view in aView.subviews )
{
if ([view respondsToSelector:@selector(setHighlighted:)]) {
- NSMutableDictionary * info = (NSMutableDictionary *) CFDictionaryGetValue( _selectionColorInfo, view );
+ NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
if ( info != nil )
{
id value = [info objectForKey: @"highlighted"];
@@ -394,7 +382,6 @@ - (void) _beginBackgroundHighlight: (BOOL) highlightOn animated: (BOOL) animated
if ( _fadeTimer != nil )
{
[_fadeTimer invalidate];
- [_fadeTimer release];
}
_fadeTimer = [[NSTimer alloc] initWithFireDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]
@@ -529,8 +516,7 @@ - (void) setBackgroundView: (UIView *) aView
if ( _backgroundView.superview == self )
[_backgroundView removeFromSuperview];
- [_backgroundView release];
- _backgroundView = [aView retain];
+ _backgroundView = aView;
_backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
@@ -572,7 +558,6 @@ - (void) layoutSubviews
else if ( _bottomSeparatorView != nil )
{
[_bottomSeparatorView removeFromSuperview];
- [_bottomSeparatorView release];
_bottomSeparatorView = nil;
}
@@ -592,7 +577,6 @@ - (void) layoutSubviews
else if ( _rightSeparatorView != nil )
{
[_rightSeparatorView removeFromSuperview];
- [_rightSeparatorView release];
_rightSeparatorView = nil;
}
}
@@ -604,8 +588,6 @@ - (void) layoutSubviews
- (void) setSelectionGlowColor: (UIColor *) aColor
{
- [aColor retain];
- [_selectionGlowColor release];
_selectionGlowColor = aColor;
_cellFlags.selectionGlowColorSet = (aColor == nil ? 0 : 1);
@@ -619,8 +601,7 @@ - (void) setSelectedBackgroundView: (UIView *) aView
if ( _selectedBackgroundView.superview == self )
[_selectedBackgroundView removeFromSuperview];
- [_selectedBackgroundView release];
- _selectedBackgroundView = [aView retain];
+ _selectedBackgroundView = aView;
_selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
@@ -665,7 +646,7 @@ @implementation AQGridViewCell (AQGridViewCellPrivate)
- (UIColor *) separatorColor
{
- return ( [[_separatorColor retain] autorelease] );
+ return ( _separatorColor );
}
- (void) setSeparatorColor: (UIColor *) color
@@ -673,8 +654,7 @@ - (void) setSeparatorColor: (UIColor *) color
if ( _separatorColor == color )
return;
- [_separatorColor release];
- _separatorColor = [color retain];
+ _separatorColor = color;
_bottomSeparatorView.backgroundColor = _separatorColor;
_rightSeparatorView.backgroundColor = _separatorColor;
4 Classes/AQGridViewController.m
View
@@ -57,7 +57,6 @@ - (void) loadView
{
AQGridView * aView = [[AQGridView alloc] initWithFrame: CGRectZero];
self.gridView = aView;
- [aView release];
[self _sharedGridViewDefaultSetup];
}
@@ -152,9 +151,6 @@ - (void)viewDidUnload {
}
-- (void)dealloc {
- [super dealloc];
-}
#pragma mark -
#pragma mark Grid View Data Source
51 Classes/AQGridViewUpdateInfo.m
View
@@ -66,23 +66,10 @@ - (id) initWithOldGridData: (AQGridViewData *) oldGridData forGridView: (AQGridV
- (void) dealloc
{
- [_insertItems release];
- [_deleteItems release];
- [_reloadItems release];
- [_moveItems release];
- [_insertedIndices release];
- [_deletedIndices release];
- [_reloadedIndices release];
- [_oldMovedIndices release];
- [_newMovedIndices release];
- [_oldGridData release];
- [_newGridData release];
if ( _oldToNewIndexMap != NULL )
- NSZoneFree( [self zone], _oldToNewIndexMap );
+ free( _oldToNewIndexMap );
if ( _newToOldIndexMap != NULL )
- NSZoneFree( [self zone], _newToOldIndexMap );
- [_onlyMovedIndices release];
- [super dealloc];
+ free( _newToOldIndexMap );
}
- (NSMutableArray *) updateItemArrayForAction: (AQGridViewUpdateAction) action
@@ -120,7 +107,6 @@ - (void) updateItemsAtIndices: (NSIndexSet *) indices
action: action
animation: animation];
[array addObject: item];
- [item release];
i = [indices indexGreaterThanIndex: i];
}
@@ -136,7 +122,6 @@ - (void) moveItemAtIndex: (NSUInteger) index
animation: animation];
item.newIndex = newIndex;
[array addObject: item];
- [item release];
}
- (NSUInteger) numberOfUpdates
@@ -191,7 +176,7 @@ - (void) updateNewGridDataAndCreateMappingTables
#else
NSUInteger count = _oldGridData.numberOfItems;
#endif
- _oldToNewIndexMap = NSZoneMalloc( [self zone], count * sizeof(NSUInteger) );
+ _oldToNewIndexMap = malloc( count * sizeof(NSUInteger) );
#if GUARD_ITEMS
memset(_oldToNewIndexMap, 0x55, count * sizeof(NSUInteger));
#endif
@@ -212,7 +197,7 @@ - (void) updateNewGridDataAndCreateMappingTables
#else
NSUInteger count = _newGridData.numberOfItems;
#endif
- _newToOldIndexMap = NSZoneMalloc( [self zone], count * sizeof(NSUInteger) );
+ _newToOldIndexMap = malloc( count * sizeof(NSUInteger) );
#if GUARD_ITEMS
memset(_newToOldIndexMap, 0x55, count * sizeof(NSUInteger));
#endif
@@ -358,8 +343,6 @@ - (void) updateNewGridDataAndCreateMappingTables
}
}
- [oldToNewIndices release];
- [newToOldIndices release];
}
- (void) cleanupUpdateItems
@@ -450,27 +433,27 @@ - (NSUInteger) newIndexForOldIndex: (NSUInteger) oldIndex
- (NSArray *) sortedInsertItems
{
- return ( [[_insertItems copy] autorelease] );
+ return ( [_insertItems copy] );
}
- (NSArray *) sortedDeleteItems
{
- return ( [[_deleteItems copy] autorelease] );
+ return ( [_deleteItems copy] );
}
- (NSArray *) sortedMoveItems
{
- return ( [[_moveItems copy] autorelease] );
+ return ( [_moveItems copy] );
}
- (NSArray *) sortedReloadItems
{
- return ( [[_reloadItems copy] autorelease] );
+ return ( [_reloadItems copy] );
}
- (AQGridViewData *) newGridViewData
{
- return ( [[_newGridData retain] autorelease] );
+ return ( _newGridData );
}
- (NSUInteger) numberOfItemsAfterUpdates
@@ -487,7 +470,7 @@ - (UIImageView *) _imageViewForView: (UIView *) view
UIGraphicsEndImageContext();
- return ( [result autorelease] );
+ return ( result );
}
- (UIImageView *) animateDeletionForCell: (AQGridViewCell *) cell withAnimation: (AQGridViewItemAnimation) animation
@@ -635,7 +618,6 @@ - (void) animateInsertionForCell: (AQGridViewCell *) cell withAnimation: (AQGrid
{
[cell setValue: [itemsToSetBeforeAnimation objectForKey: keyPath] forKey: keyPath];
}
- [itemsToSetBeforeAnimation release];
[UIView setAnimationsEnabled: YES];
for ( NSString * keyPath in itemsToAnimate )
@@ -643,7 +625,6 @@ - (void) animateInsertionForCell: (AQGridViewCell *) cell withAnimation: (AQGrid
[cell setValue: [itemsToAnimate objectForKey: keyPath] forKey: keyPath];
}
- [itemsToAnimate release];
}
- (void) animateReloadForCell: (AQGridViewCell *) newCell originalCell: (AQGridViewCell *) originalCell withAnimation: (AQGridViewItemAnimation) animation
@@ -773,7 +754,7 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
{
// only store real cells here
if ( [item.animatingView isKindOfClass: [AQGridViewCell class]] )
- CFDictionaryAddValue( animatingCellTable, (void *)item.index, item );
+ CFDictionaryAddValue( animatingCellTable, (void *)item.index, objc_unretainedPointer(item) );
}
// a set of the indices (in old grid data) for all currently-known cells which are now or will become visible
@@ -787,13 +768,12 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
NSMutableIndexSet * movingSet = [[NSMutableIndexSet alloc] initWithIndexSet: oldVisibleIndices];
[movingSet addIndexes: oldIndicesOfAllVisibleCells];
- [oldIndicesOfAllVisibleCells release];
// most items were just moved from one location to another
for ( NSUInteger oldIndex = [movingSet firstIndex]; oldIndex != NSNotFound; oldIndex = [movingSet indexGreaterThanIndex: oldIndex] )
{
NSUInteger newIndex = _oldToNewIndexMap[oldIndex];
- AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)CFDictionaryGetValue( animatingCellTable, (void *)oldIndex );
+ AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)objc_unretainedObject(CFDictionaryGetValue( animatingCellTable, (void *)oldIndex ));
AQGridViewCell * cell = (AQGridViewCell *)animatingItem.animatingView;
if ( cell == nil )
@@ -843,7 +823,6 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
[_gridView delegateWillDisplayCell: cell atIndex: newIndex];
}
- [movingSet release];
// delete old items first
if ( _deleteItems.count != 0 )
@@ -853,7 +832,7 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
{
if ( [oldVisibleIndices containsIndex: item.originalIndex] )
{
- AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)CFDictionaryGetValue( animatingCellTable, (void *)item.originalIndex );
+ AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)objc_unretainedObject(CFDictionaryGetValue( animatingCellTable, (void *)item.originalIndex ));
AQGridViewCell * deletingCell = (AQGridViewCell *)animatingItem.animatingView;
if ( deletingCell == nil )
@@ -898,7 +877,7 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
if ( [newVisibleIndices containsIndex: item.index] == NO )
continue;
- AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)CFDictionaryGetValue( animatingCellTable, (void *)item.originalIndex );
+ AQGridViewAnimatorItem * animatingItem = (AQGridViewAnimatorItem *)objc_unretainedObject(CFDictionaryGetValue( animatingCellTable, (void *)item.originalIndex ));
AQGridViewCell * origCell = (AQGridViewCell *)animatingItem.animatingView;
if ( origCell == nil )
@@ -930,7 +909,7 @@ - (NSSet *) animateCellUpdatesUsingVisibleContentRect: (CGRect) contentRect
CFRelease( animatingCellTable );
- return ( [newVisibleCells autorelease] );
+ return ( newVisibleCells );
}
@end
3  Classes/NSIndexSet+AQIndexesOutsideSet.m
View
@@ -16,8 +16,7 @@ - (NSIndexSet *) aq_indexesOutsideIndexSet: (NSIndexSet *) otherSet
NSMutableIndexSet * mutable = [self mutableCopy];
[mutable removeIndexes: otherSet];
NSIndexSet * result = [mutable copy];
- [mutable release];
- return ( [result autorelease] );
+ return ( result );
}
@end
5 Examples/ImageDemo/Classes/ImageDemoAppDelegate.m
View
@@ -55,11 +55,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
-- (void)dealloc {
- [viewController release];
- [window release];
- [super dealloc];
-}
@end
4 Examples/ImageDemo/Classes/ImageDemoCellChooser.h
View
@@ -43,12 +43,12 @@
@interface ImageDemoCellChooser : UITableViewController
{
NSArray * _itemTitles;
- id<ImageDemoCellChooserDelegate> __weak _delegate;
+ id<ImageDemoCellChooserDelegate> __unsafe_unretained _delegate;
}
- (id) initWithItemTitles: (NSArray *) titles;
-@property (nonatomic, assign) id<ImageDemoCellChooserDelegate> __weak delegate;
+@property (nonatomic, assign) id<ImageDemoCellChooserDelegate> delegate;
@end
7 Examples/ImageDemo/Classes/ImageDemoCellChooser.m
View
@@ -57,11 +57,6 @@ - (id) initWithItemTitles: (NSArray *) titles
return ( self );
}
-- (void) dealloc
-{
- [_itemTitles release];
- [super dealloc];
-}
#pragma mark -
#pragma mark View lifecycle
@@ -129,7 +124,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [_itemTitles objectAtIndex: indexPath.row];
6 Examples/ImageDemo/Classes/ImageDemoFilledCell.m
View
@@ -64,12 +64,6 @@ - (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) aReuseIdentif
return ( self );
}
-- (void) dealloc
-{
- [_imageView release];
- [_title release];
- [super dealloc];
-}
- (UIImage *) image
{
5 Examples/ImageDemo/Classes/ImageDemoGridViewCell.m
View
@@ -52,11 +52,6 @@ - (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) aReuseIdentif
return ( self );
}
-- (void) dealloc
-{
- [_imageView release];
- [super dealloc];
-}
- (CALayer *) glowSelectionLayer
{
24 Examples/ImageDemo/Classes/ImageDemoViewController.m
View
@@ -64,7 +64,6 @@ - (void) viewDidLoad
ImageDemoCellChooser * chooser = [[ImageDemoCellChooser alloc] initWithItemTitles: [NSArray arrayWithObjects: NSLocalizedString(@"Plain", @""), NSLocalizedString(@"Filled", @""), nil]];
chooser.delegate = self;
_menuPopoverController = [[UIPopoverController alloc] initWithContentViewController: chooser];
- [chooser release];
if ( _orderedImageNames != nil )
return;
@@ -84,7 +83,6 @@ - (void) viewDidLoad
_orderedImageNames = [[allImageNames sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)] copy];
_imageNames = [_orderedImageNames copy];
- [allImageNames release];
[self.gridView reloadData];
}
@@ -100,17 +98,9 @@ - (void) viewDidUnload
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.gridView = nil;
- [_menuPopoverController release]; _menuPopoverController = nil;
+ _menuPopoverController = nil;
}
-- (void) dealloc
-{
- [_gridView release];
- [_imageNames release];
- [_orderedImageNames release];
- [_menuPopoverController release];
- [super dealloc];
-}
- (IBAction) shuffle
{
@@ -135,13 +125,10 @@ - (IBAction) shuffle
[sourceArray removeObjectAtIndex: index];
}
- [_imageNames release];
_imageNames = [destArray copy];
[self.gridView endUpdates];
- [sourceArray release];
- [destArray release];
}
- (IBAction) resetOrder
@@ -160,7 +147,6 @@ - (IBAction) resetOrder
[self.gridView endUpdates];
- [_imageNames release];
_imageNames = [_orderedImageNames copy];
}
@@ -249,8 +235,8 @@ - (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSU
ImageDemoGridViewCell * plainCell = (ImageDemoGridViewCell *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier];
if ( plainCell == nil )
{
- plainCell = [[[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
- reuseIdentifier: PlainCellIdentifier] autorelease];
+ plainCell = [[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
+ reuseIdentifier: PlainCellIdentifier];
plainCell.selectionGlowColor = [UIColor blueColor];
}
@@ -265,8 +251,8 @@ - (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSU
ImageDemoFilledCell * filledCell = (ImageDemoFilledCell *)[aGridView dequeueReusableCellWithIdentifier: FilledCellIdentifier];
if ( filledCell == nil )
{
- filledCell = [[[ImageDemoFilledCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
- reuseIdentifier: FilledCellIdentifier] autorelease];
+ filledCell = [[ImageDemoFilledCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
+ reuseIdentifier: FilledCellIdentifier];
filledCell.selectionStyle = AQGridViewCellSelectionStyleBlueGray;
}
6 Examples/ImageDemo/ImageDemo.xcodeproj/project.pbxproj
View
@@ -410,12 +410,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ImageDemo_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "ImageDemo-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = ImageDemo;
};
name = Debug;
@@ -424,10 +427,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ImageDemo_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "ImageDemo-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = ImageDemo;
VALIDATE_PRODUCT = YES;
};
7 Examples/ImageDemo/main.m
View
@@ -10,8 +10,9 @@
int main(int argc, char *argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- int retVal = UIApplicationMain(argc, argv, nil, nil);
- [pool release];
+ int retVal;
+ @autoreleasepool {
+ retVal = UIApplicationMain(argc, argv, nil, nil);
+ }
return retVal;
}
5 Examples/SpringBoard/Classes/SpringBoardAppDelegate.m
View
@@ -55,11 +55,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
-- (void)dealloc {
- [viewController release];
- [window release];
- [super dealloc];
-}
@end
5 Examples/SpringBoard/Classes/SpringBoardIconCell.m
View
@@ -71,11 +71,6 @@ - (id) initWithFrame: (CGRect) frame reuseIdentifier:(NSString *) reuseIdentifie
return ( self );
}
-- (void) dealloc
-{
- [_iconView release];
- [super dealloc];
-}
- (UIImage *) icon
{
20 Examples/SpringBoard/Classes/SpringBoardViewController.m
View
@@ -82,7 +82,6 @@ - (void) viewDidLoad
gr.minimumPressDuration = 0.5;
gr.delegate = self;
[_gridView addGestureRecognizer: gr];
- [gr release];
if ( _icons == nil )
{
@@ -207,10 +206,9 @@ - (void) moveActionGestureRecognizerStateChanged: (UIGestureRecognizer *) recogn
}
// update the data store
- id obj = [[_icons objectAtIndex: _dragOriginIndex] retain];
+ id obj = [_icons objectAtIndex: _dragOriginIndex];
[_icons removeObjectAtIndex: _dragOriginIndex];
[_icons insertObject: obj atIndex: index];
- [obj release];
if ( index != _emptyCellIndex )
{
@@ -342,10 +340,8 @@ - (void) finishedSnap: (NSString *) animationID finished: (NSNumber *) finished
// dismiss our copy of the cell
[_draggingCell removeFromSuperview];
- [_draggingCell release];
_draggingCell = nil;
- [indices release];
}
#pragma mark -
@@ -369,8 +365,8 @@ - (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUI
{
// must be the SAME SIZE AS THE OTHERS
// Yes, this is probably a bug. Sigh. Look at -[AQGridView fixCellsFromAnimation] to fix
- hiddenCell = [[[AQGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0)
- reuseIdentifier: EmptyIdentifier] autorelease];
+ hiddenCell = [[AQGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0)
+ reuseIdentifier: EmptyIdentifier];
}
hiddenCell.hidden = YES;
@@ -380,7 +376,7 @@ - (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUI
SpringBoardIconCell * cell = (SpringBoardIconCell *)[gridView dequeueReusableCellWithIdentifier: CellIdentifier];
if ( cell == nil )
{
- cell = [[[SpringBoardIconCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0) reuseIdentifier: CellIdentifier] autorelease];
+ cell = [[SpringBoardIconCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0) reuseIdentifier: CellIdentifier];
}
cell.icon = [_icons objectAtIndex: index];
@@ -397,14 +393,8 @@ - (void) viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
- [_gridView release]; _gridView = nil;
+ _gridView = nil;
}
-- (void) dealloc
-{
- [_icons release];
- [_gridView release];
- [super dealloc];
-}
@end
6 Examples/SpringBoard/SpringBoard.xcodeproj/project.pbxproj
View
@@ -265,12 +265,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SpringBoard_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "SpringBoard-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = SpringBoard;
};
name = Debug;
@@ -279,10 +282,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SpringBoard_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "SpringBoard-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = SpringBoard;
VALIDATE_PRODUCT = YES;
};
7 Examples/SpringBoard/main.m
View
@@ -10,8 +10,9 @@
int main(int argc, char *argv[]) {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- int retVal = UIApplicationMain(argc, argv, nil, nil);
- [pool release];
+ int retVal;
+ @autoreleasepool {
+ retVal = UIApplicationMain(argc, argv, nil, nil);
+ }
return retVal;
}
Please sign in to comment.
Something went wrong with that request. Please try again.