Skip to content

Commit f22e64d

Browse files
committed
fix: make FlagSet reusable
1 parent c94c99a commit f22e64d

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

Sources/Features/FoldersCompare/CompareItem/CompareItem.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
typealias CompareItemComparison = (CompareItem, CompareItem) -> ComparisonResult
1010

11-
// swiftlint:disable file_length
1211
public class CompareItem: NSObject {
13-
struct FileOptions: OptionSet {
12+
struct FileOptions: FlagSet {
1413
var rawValue: Int
1514

1615
static let isFile = FileOptions(rawValue: 1 << 0)
@@ -20,20 +19,6 @@ public class CompareItem: NSObject {
2019
static let isResourceFork = FileOptions(rawValue: 1 << 4)
2120
static let isLocked = FileOptions(rawValue: 1 << 5)
2221
static let isValidFile = FileOptions(rawValue: 1 << 6)
23-
24-
subscript(option: FileOptions) -> Bool {
25-
get {
26-
contains(option)
27-
}
28-
29-
set {
30-
if newValue {
31-
insert(option)
32-
} else {
33-
remove(option)
34-
}
35-
}
36-
}
3722
}
3823

3924
var linkedItem: CompareItem?
@@ -401,5 +386,3 @@ public class CompareItem: NSObject {
401386
isFiltered = false
402387
}
403388
}
404-
405-
// swiftlint:enable file_length
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// FlagSet.swift
3+
// VisualDiffer
4+
//
5+
// Created by davide ficano on 31/12/25.
6+
// Copyright (c) 2025 visualdiffer.com
7+
//
8+
9+
public protocol FlagSet: OptionSet {}
10+
11+
public extension FlagSet {
12+
@inlinable
13+
subscript(option: Self.Element) -> Bool {
14+
get {
15+
contains(option)
16+
}
17+
set {
18+
if newValue {
19+
insert(option)
20+
} else {
21+
remove(option)
22+
}
23+
}
24+
}
25+
}

VisualDiffer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@
508508
55F9E79A2EDD5DBD001218C7 /* DiffResult.Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F9E7992EDD5DAD001218C7 /* DiffResult.Options.swift */; };
509509
55F9E79C2EDD6221001218C7 /* WhitespacesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F9E79B2EDD6221001218C7 /* WhitespacesTests.swift */; };
510510
55FD7E28180C484500CF473C /* prefs_folder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 55FD7E25180C484500CF473C /* prefs_folder@2x.png */; };
511+
55FE894A2F054B260003864A /* FlagSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55FE89492F054B260003864A /* FlagSet.swift */; };
511512
775DFF38067A968500C5B868 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
512513
8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
513514
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
@@ -1108,6 +1109,7 @@
11081109
55F9E79B2EDD6221001218C7 /* WhitespacesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhitespacesTests.swift; sourceTree = "<group>"; };
11091110
55FC15F22557CD000075E30D /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = System/Library/Frameworks/ScriptingBridge.framework; sourceTree = SDKROOT; };
11101111
55FD7E25180C484500CF473C /* prefs_folder@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "prefs_folder@2x.png"; sourceTree = "<group>"; };
1112+
55FE89492F054B260003864A /* FlagSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagSet.swift; sourceTree = "<group>"; };
11111113
7788DA0506752A1600599AAD /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
11121114
8D15AC360486D014006FF6A4 /* VisualDiffer-Info.plist */ = {isa = PBXFileReference; explicitFileType = text.plist.xml; fileEncoding = 4; path = "VisualDiffer-Info.plist"; sourceTree = "<group>"; };
11131115
8D15AC370486D014006FF6A4 /* VisualDiffer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VisualDiffer.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2256,6 +2258,7 @@
22562258
553740FA2E9372DF00AB56D0 /* OptionSet */ = {
22572259
isa = PBXGroup;
22582260
children = (
2261+
55FE89492F054B260003864A /* FlagSet.swift */,
22592262
553740F92E9372DF00AB56D0 /* OptionSet+Toggle.swift */,
22602263
);
22612264
path = OptionSet;
@@ -3223,6 +3226,7 @@
32233226
55916A102E8A814200ED6629 /* MyDocument.xcdatamodeld in Sources */,
32243227
553741792E9372DF00AB56D0 /* NSAppearance+DarkMode.swift in Sources */,
32253228
5537417A2E9372DF00AB56D0 /* QLPreviewPanel.swift in Sources */,
3229+
55FE894A2F054B260003864A /* FlagSet.swift in Sources */,
32263230
5537417B2E9372DF00AB56D0 /* TrustedPathsPreferencesPanel.swift in Sources */,
32273231
5537417C2E9372DF00AB56D0 /* TouchPickersStackView.swift in Sources */,
32283232
5537417D2E9372DF00AB56D0 /* BasePreferences.swift in Sources */,

0 commit comments

Comments
 (0)