Permalink
Browse files

Support compiling with ARC under Clang using ifdefs.

  • Loading branch information...
1 parent d5aa8ae commit da1479062a67bc6bd9a57f9e8b2af2a23f67cb8a @atombender atombender committed Feb 5, 2013
Showing with 20 additions and 3 deletions.
  1. +20 −3 MASPreferencesWindowController.m
@@ -38,7 +38,11 @@ - (id)initWithViewControllers:(NSArray *)viewControllers title:(NSString *)title
{
if ((self = [super initWithWindowNibName:@"MASPreferencesWindow"]))
{
+#if __has_feature(objc_arc)
+ _viewControllers = viewControllers;
+#else
_viewControllers = [viewControllers retain];
+#endif
_minimumViewRects = [[NSMutableDictionary alloc] init];
_title = [title copy];
}
@@ -49,13 +53,13 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[self window] setDelegate:nil];
-
+#if !__has_feature(objc_arc)
[_viewControllers release];
[_selectedViewController release];
[_minimumViewRects release];
[_title release];
-
[super dealloc];
+#endif
}
#pragma mark -
@@ -160,7 +164,10 @@ - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString
toolbarItem.target = self;
toolbarItem.action = @selector(toolbarItemDidClick:);
}
- return [toolbarItem autorelease];
+#if !__has_feature(objc_arc)
+ [toolbarItem autorelease];
+#endif
+ return toolbarItem;
}
#pragma mark -
@@ -216,11 +223,17 @@ - (void)setSelectedViewController:(NSViewController <MASPreferencesViewControlle
return;
}
+#if __has_feature(objc_arc)
+ [self.window setContentView:[[NSView alloc] init]];
+#else
[self.window setContentView:[[[NSView alloc] init] autorelease]];
+#endif
if ([_selectedViewController respondsToSelector:@selector(viewDidDisappear)])
[_selectedViewController viewDidDisappear];
+#if !__has_feature(objc_arc)
[_selectedViewController release];
+#endif
_selectedViewController = nil;
}
@@ -267,7 +280,11 @@ - (void)setSelectedViewController:(NSViewController <MASPreferencesViewControlle
[self.window setFrame:newFrame display:YES animate:[self.window isVisible]];
+#if __has_feature(objc_arc)
+ _selectedViewController = controller;
+#else
_selectedViewController = [controller retain];
+#endif
if ([controller respondsToSelector:@selector(viewWillAppear)])
[controller viewWillAppear];

2 comments on commit da14790

Collaborator

sorbits commented on da14790 Feb 20, 2013

@alexstaubo This commit complicates future maintenance.

I would suggest instead wrapping the code in retain/(auto)release calls and define them as no-ops for when ARC is enabled.

See XCMemoryUtils.h for an example of such macros.

Also see how that file tests for ARC: We could be building on a compiler w/o the __has_feature function, so we need to test for that as well.

Contributor

atombender replied Feb 20, 2013

Not sure what kind of future maintenance you are thinking of, but your project is 302 loc, not exactly a maintenance nightmare? What makes most sense in my view is to fork the code into a (frozen) legacy branch and a current one. Unless you plan on maintaining the legacy non-ARC version?

Please sign in to comment.