Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Support compiling with ARC under Clang using ifdefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Staubo committed Feb 5, 2013
1 parent d5aa8ae commit da14790
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions MASPreferencesWindowController.m
Expand Up @@ -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];
}
Expand All @@ -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 -
Expand Down Expand Up @@ -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 -
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];

Expand Down

2 comments on commit da14790

@sorbits
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@atombender
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.