Skip to content

Commit d8a83c2

Browse files
chbeerhannesa2
authored andcommitted
Swift Package Support, switch to ARC
1 parent dea7214 commit d8a83c2

11 files changed

+67
-33
lines changed

Package.swift

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// swift-tools-version: 5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "MGScopeBar",
8+
defaultLocalization: "en",
9+
platforms: [
10+
.macOS(.v11)
11+
],
12+
products: [
13+
// Products define the executables and libraries a package produces, and make them visible to other packages.
14+
.library(
15+
name: "MGScopeBar",
16+
targets: ["MGScopeBar"]),
17+
],
18+
dependencies: [
19+
// Dependencies declare other packages that this package depends on.
20+
// .package(url: /* package url */, from: "1.0.0"),
21+
],
22+
targets: [
23+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
24+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
25+
.target(
26+
name: "MGScopeBar",
27+
dependencies: [],
28+
resources: [
29+
.process("Resources")
30+
]),
31+
.testTarget(
32+
name: "MGScopeBarTests",
33+
dependencies: ["MGScopeBar"]),
34+
]
35+
)

ReadMe.txt README.md

File renamed without changes.
File renamed without changes.

MGRecessedPopUpButtonCell.m Sources/MGScopeBar/MGRecessedPopUpButtonCell.m

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ - (id)initTextCell:(NSString *)title pullsDown:(BOOL)pullsDown
2626
return self;
2727
}
2828

29-
30-
- (void)dealloc
31-
{
32-
[recessedButton release];
33-
[super dealloc];
34-
}
35-
36-
3729
- (void)drawTitleWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
3830
{
3931
// Inset title rect since its position is broken when NSPopUpButton

MGScopeBar.h Sources/MGScopeBar/MGScopeBar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "MGScopeBarDelegateProtocol.h"
1111

1212
@interface MGScopeBar : NSView {
13-
IBOutlet id <MGScopeBarDelegate, NSObject> delegate; // weak ref.
13+
IBOutlet __unsafe_unretained id <MGScopeBarDelegate, NSObject> delegate; // weak ref.
1414
NSMutableArray *_separatorPositions; // x-coords of separators, indexed by their group-number.
1515
NSMutableArray *_groups; // groups of items.
1616
NSView *_accessoryView; // weak ref since it's a subview.

MGScopeBar.m Sources/MGScopeBar/MGScopeBar.m

+7-24
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ - (void)dealloc
9999
[_accessoryView removeFromSuperview];
100100
_accessoryView = nil; // weak ref
101101
}
102-
[_separatorPositions release];
103-
[_groups release];
104-
[_identifiers release];
105-
[_selectedItems release];
106-
107-
[super dealloc];
108102
}
109103

110104

@@ -124,15 +118,10 @@ - (void)reloadData
124118

125119
NSArray *subviews = [[self subviews] copy]; // so we don't mutate the collection we're iterating over.
126120
[subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
127-
[subviews release]; // because copies are retained.
128121

129-
[_separatorPositions release];
130122
_separatorPositions = nil;
131-
[_groups release];
132123
_groups = nil;
133-
[_identifiers release];
134124
_identifiers = nil;
135-
[_selectedItems release];
136125
_selectedItems = nil;
137126
_firstCollapsedGroup = NSNotFound;
138127
_lastWidth = NSNotFound;
@@ -187,7 +176,6 @@ - (void)reloadData
187176
ctrlRect.size = [labelField frame].size;
188177
[labelField setFrame:ctrlRect];
189178
[self addSubview:labelField];
190-
[labelField release];
191179

192180
xCoord += ctrlRect.size.width + SCOPE_BAR_ITEM_SPACING;
193181

@@ -712,7 +700,7 @@ - (NSButton *)buttonForItem:(NSString *)identifier inGroup:(NSInteger)groupNumbe
712700

713701
[self setControl:button forIdentifier:identifier inGroup:groupNumber];
714702

715-
return [button autorelease];
703+
return button;
716704
}
717705

718706

@@ -727,7 +715,7 @@ - (NSMenuItem *)menuItemForItem:(NSString *)identifier inGroup:(NSInteger)groupN
727715

728716
[self setControl:menuItem forIdentifier:identifier inGroup:groupNumber];
729717

730-
return [menuItem autorelease];
718+
return menuItem;
731719
}
732720

733721

@@ -742,12 +730,10 @@ - (NSPopUpButton *)popupButtonForGroup:(NSDictionary *)group
742730
if (multiSelect) {
743731
MGRecessedPopUpButtonCell *cell = [[MGRecessedPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
744732
[popup setCell:cell];
745-
[cell release];
746733

747734
[[popup cell] setUsesItemFromMenu:NO];
748735
NSMenuItem *titleItem = [[NSMenuItem alloc] init];
749736
[[popup cell] setMenuItem:titleItem];
750-
[titleItem release];
751737
}
752738

753739
// Configure appearance and behaviour.
@@ -782,7 +768,7 @@ - (NSPopUpButton *)popupButtonForGroup:(NSDictionary *)group
782768
popFrame.origin.y = ceil(([self frame].size.height - popFrame.size.height) / 2.0);
783769
[popup setFrame:popFrame];
784770

785-
return [popup autorelease];
771+
return popup;
786772
}
787773

788774

@@ -794,7 +780,7 @@ - (void)setControl:(NSObject *)control forIdentifier:(NSString *)identifier inGr
794780

795781
NSMutableArray *identArray = [_identifiers objectForKey:identifier];
796782
if (!identArray) {
797-
identArray = [[[NSMutableArray alloc] initWithCapacity:groupNumber + 1] autorelease];
783+
identArray = [[NSMutableArray alloc] initWithCapacity:groupNumber + 1];
798784
[_identifiers setObject:identArray forKey:identifier];
799785
}
800786

@@ -872,8 +858,8 @@ - (void)updateMenuTitleForGroupAtIndex:(NSInteger)groupNumber
872858
- (void)drawRect:(NSRect)rect
873859
{
874860
// Draw gradient background.
875-
NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:SCOPE_BAR_START_COLOR_GRAY
876-
endingColor:SCOPE_BAR_END_COLOR_GRAY] autorelease];
861+
NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:SCOPE_BAR_START_COLOR_GRAY
862+
endingColor:SCOPE_BAR_END_COLOR_GRAY];
877863
[gradient drawInRect:[self bounds] angle:90.0];
878864

879865
// Draw border.
@@ -932,7 +918,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt
932918
BOOL informDelegate = YES;
933919

934920
if (group) {
935-
[group retain];
936921
NSDisableScreenUpdates();
937922

938923
// We found the group which this item belongs to. Obtain selection-mode and identifiers.
@@ -956,7 +941,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt
956941
informDelegate = NO;
957942
}
958943
}
959-
[groupSelections release];
960944
}
961945

962946
// Change selected state of this item.
@@ -967,7 +951,6 @@ - (void)setSelected:(BOOL)selected forItem:(NSString *)identifier inGroup:(NSInt
967951
[self updateMenuTitleForGroupAtIndex:groupNumber];
968952
}
969953

970-
[group release];
971954
NSEnableScreenUpdates();
972955
}
973956
}
@@ -1012,7 +995,7 @@ - (void)updateSelectedState:(BOOL)selected forItem:(NSString *)identifier inGrou
1012995

1013996
- (NSArray *)selectedItems
1014997
{
1015-
return [[_selectedItems copy] autorelease];
998+
return [_selectedItems copy];
1016999
}
10171000
- (BOOL) isItemSelectedWithIdentifier:(NSString*)identifier inGroup:(NSInteger)groupNumber;
10181001
{
File renamed without changes.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Header.h
3+
//
4+
//
5+
// Created by Christian Beer on 29.08.22.
6+
//
7+
8+
#ifndef Header_h
9+
#define Header_h
10+
11+
#include "../MGScopeBar.h"
12+
#include "../MGRecessedPopUpButtonCell.h"
13+
14+
#endif /* Header_h */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import XCTest
2+
@testable import MGScopeBar
3+
4+
final class MGScopeBarTests: XCTestCase {
5+
func testExample() throws {
6+
// This is an example of a functional test case.
7+
// Use XCTAssert and related functions to verify your tests produce the correct
8+
// results.
9+
}
10+
}

0 commit comments

Comments
 (0)