Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Pragma Marks for ARC/Non-ARC projects #25

Open
wants to merge 2 commits into from

1 participant

Mitchell
Mitchell

Just helps to not require developers to have to add the flags to the classes as well as, just adding the flags doesn't result in optimum performance, made a change that helps with an error with just adding the compiler flags.

Mitch Clay added some commits
Mitch Clay Code is now portable between ARC and non-ARC projects without compile…
…r flags needing to be placed on the classes
6dd1e2c
Mitch Clay Code is now portable between ARC and non-ARC projects without compile…
…r flags needing to be placed on the classes
09a73ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. Code is now portable between ARC and non-ARC projects without compile…

    Mitch Clay authored
    …r flags needing to be placed on the classes
  2. Code is now portable between ARC and non-ARC projects without compile…

    Mitch Clay authored
    …r flags needing to be placed on the classes
This page is out of date. Refresh to see the latest.
25 DTGridView Project/Classes/DTGridViewAppDelegate.m
View
@@ -25,20 +25,24 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
vc.title = @"DTGridView";
vc.tableView.delegate = self;
vc.tableView.dataSource = self;
+#if __has_feature(objc_arc)
+#else
[vc release];
-
+#endif
[window addSubview:navigationController.view];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
-
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
+#endif
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
@@ -64,8 +68,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell)
+#if __has_feature(objc_arc)
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
+#else
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
-
+#endif
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSString *cellText = nil;
@@ -89,19 +96,31 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
if (indexPath.section == 0 && indexPath.row == 0) {
DTLicenseAgreementViewController *vc = [[DTLicenseAgreementViewController alloc] init];
[navigationController pushViewController:vc animated:YES];
+#if __has_feature(objc_arc)
+#else
[vc release];
+#endif
} else if (indexPath.section == 1 && indexPath.row == 0) {
DTGridViewExampleDataSourceAndDelegate *vc = [[DTGridViewExampleDataSourceAndDelegate alloc] init];
[navigationController pushViewController:vc animated:YES];
+#if __has_feature(objc_arc)
+#else
[vc release];
+#endif
} else if (indexPath.section == 1 && indexPath.row == 1) {
DTInfiniteGridViewExampleViewController *vc = [[DTInfiniteGridViewExampleViewController alloc] init];
[navigationController pushViewController:vc animated:YES];
+#if __has_feature(objc_arc)
+#else
[vc release];
+#endif
} else if (indexPath.section == 1 && indexPath.row == 2) {
DTSnapGridViewExampleViewController *vc = [[DTSnapGridViewExampleViewController alloc] init];
[navigationController pushViewController:vc animated:YES];
+#if __has_feature(objc_arc)
+#else
[vc release];
+#endif
}
}
25 DTGridView Project/Classes/DTGridViewExampleDataSourceAndDelegate.m
View
@@ -30,16 +30,23 @@ - (id)init {
return self;
}
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[pickerView release];
[navBar release];
[colours release];
[super dealloc];
}
+#endif
- (void)viewDidLoad {
[super viewDidLoad];
- self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Scroll" style:UIBarButtonItemStyleBordered target:self action:@selector(scroll)] autorelease];
+#if __has_feature(objc_arc)
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Scroll" style:UIBarButtonItemStyleBordered target:self action:@selector(scroll)];
+#else
+ self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Scroll" style:UIBarButtonItemStyleBordered target:self action:@selector(scroll)] autorelease];
+#endif
self.title = @"DTGridView";
self.gridView.delegate = self;
self.gridView.dataSource = self;
@@ -58,10 +65,18 @@ - (void)scroll {
navBar.barStyle = UIBarStyleBlack;
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Scroll GridView"];
- item.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Scroll To" style:UIBarButtonItemStylePlain target:self action:@selector(scrollTo)] autorelease];
- item.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(endScrolling)] autorelease];
+#if __has_feature(objc_arc)
+ item.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Scroll To" style:UIBarButtonItemStylePlain target:self action:@selector(scrollTo)];
+ item.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(endScrolling)];
+#else
+ item.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Scroll To" style:UIBarButtonItemStylePlain target:self action:@selector(scrollTo)] autorelease];
+ item.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(endScrolling)] autorelease];
+#endif
[navBar pushNavigationItem:item animated:NO];
+#if __has_feature(objc_arc)
+#else
[item release];
+#endif
[self.navigationController.navigationBar.superview insertSubview:navBar belowSubview:self.navigationController.navigationBar];
pickerView.dataSource = self;
@@ -147,7 +162,11 @@ - (DTGridViewCell *)gridView:(DTGridView *)gv viewForRow:(NSInteger)rowIndex col
DTGridViewCell *cell = [gv dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
+#if __has_feature(objc_arc)
+ cell = [[DTGridViewCell alloc] initWithReuseIdentifier:@"cell"];
+#else
cell = [[[DTGridViewCell alloc] initWithReuseIdentifier:@"cell"] autorelease];
+#endif
}
cell.backgroundColor = [colours objectAtIndex:(random() % 10)];
14 DTGridView Project/Classes/DTInfiniteGridViewExampleViewController.m
View
@@ -54,10 +54,12 @@ - (void)viewDidUnload {
// e.g. self.myOutlet = nil;
}
-
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[super dealloc];
}
+#endif
- (NSInteger)numberOfRowsInGridView:(DTGridView *)gridView {
return 1;
}
@@ -71,8 +73,11 @@ - (CGFloat)gridView:(DTGridView *)gv widthForCellAtRow:(NSInteger)rowIndex colum
return gv.frame.size.width / 2;
}
- (DTGridViewCell *)gridView:(DTGridView *)gv viewForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {
+#if __has_feature(objc_arc)
+ DTGridViewCell *view = [gv dequeueReusableCellWithIdentifier:@"cell"];
+#else
DTGridViewCell *view = [[gv dequeueReusableCellWithIdentifier:@"cell"] retain];
-
+#endif
if (!view)
view = [[DTGridViewCell alloc] initWithReuseIdentifier:@"cell"];
@@ -86,8 +91,11 @@ - (DTGridViewCell *)gridView:(DTGridView *)gv viewForRow:(NSInteger)rowIndex col
view.backgroundColor = [UIColor yellowColor];
else
NSLog(@"%@:%@ FAIL: %i", self, NSStringFromSelector(_cmd), columnIndex);
-
+#if __has_feature(objc_arc)
+ return view;
+#else
return [view autorelease];
+#endif
}
@end
4 DTGridView Project/Classes/DTSnapGridViewExampleViewController.m
View
@@ -35,10 +35,12 @@ - (void)viewDidUnload {
// e.g. self.myOutlet = nil;
}
-
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[super dealloc];
}
+#endif
#pragma mark DTGridViewDataSource Methods
2  DTGridView Project/DTGridView.xcodeproj/project.pbxproj
View
@@ -292,6 +292,7 @@
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;
@@ -307,6 +308,7 @@
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 = DTGridView_Prefix.pch;
86 DTGridView Project/DTGridView.xcodeproj/xcuserdata/nmmrc18.xcuserdatad/xcschemes/DTGridView.xcscheme
View
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0450"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
+ BuildableName = "DTGridView.app"
+ BlueprintName = "DTGridView"
+ ReferencedContainer = "container:DTGridView.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
+ BuildableName = "DTGridView.app"
+ BlueprintName = "DTGridView"
+ ReferencedContainer = "container:DTGridView.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
+ BuildableName = "DTGridView.app"
+ BlueprintName = "DTGridView"
+ ReferencedContainer = "container:DTGridView.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "1D6058900D05DD3D006BFB54"
+ BuildableName = "DTGridView.app"
+ BlueprintName = "DTGridView"
+ ReferencedContainer = "container:DTGridView.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
22 DTGridView Project/DTGridView.xcodeproj/xcuserdata/nmmrc18.xcuserdatad/xcschemes/xcschememanagement.plist
View
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>SchemeUserState</key>
+ <dict>
+ <key>DTGridView.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>1D6058900D05DD3D006BFB54</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
5 DTGridView Project/License Agreement/DTLicenseAgreementViewController.m
View
@@ -49,11 +49,12 @@ - (void)didReceiveMemoryWarning {
// Release anything that's not essential, such as cached data
}
-
+#if __has_feature(objc_arc)
+#else
- (void)dealloc {
[webView release]; webView = nil;
[super dealloc];
}
-
+#endif
@end
6 DTGridView Project/main.m
View
@@ -10,8 +10,14 @@
int main(int argc, char *argv[]) {
+#if __has_feature(objc_arc)
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, nil);
+ }
+#else
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
+#endif
}
4 DTGridView.h
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.
51 DTGridView.m
View
@@ -53,6 +53,8 @@ @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;
@@ -60,6 +62,7 @@ - (void)dealloc {
[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
}
}
4 DTGridViewCell.h
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;
3  DTGridViewCell.m
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;
3  DTGridViewController.m
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;
3  DTSnapGridView/DTLabelsSnapGridViewCell.m
View
@@ -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];
3  DTSnapGridView/DTSnapGridView.m
View
@@ -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];
Something went wrong with that request. Please try again.