Skip to content
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 925662f commit 6dd1e2c88ad10bfe63ab1d10a0525da7d719d0af Mitch Clay committed Nov 15, 2012
View
25 DTGridView Project/Classes/DTGridViewAppDelegate.m
@@ -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
}
}
View
25 DTGridView Project/Classes/DTGridViewExampleDataSourceAndDelegate.m
@@ -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)];
View
14 DTGridView Project/Classes/DTInfiniteGridViewExampleViewController.m
@@ -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
View
4 DTGridView Project/Classes/DTSnapGridViewExampleViewController.m
@@ -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
View
2 DTGridView Project/DTGridView.xcodeproj/project.pbxproj
@@ -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;
View
86 ...Project/DTGridView.xcodeproj/xcuserdata/nmmrc18.xcuserdatad/xcschemes/DTGridView.xcscheme
@@ -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>
View
22 ...ct/DTGridView.xcodeproj/xcuserdata/nmmrc18.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -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>
View
5 DTGridView Project/License Agreement/DTLicenseAgreementViewController.m
@@ -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
View
6 DTGridView Project/main.m
@@ -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
}

0 comments on commit 6dd1e2c

Please sign in to comment.
Something went wrong with that request. Please try again.