From f588a1e52b2ddcb2b5dd4a1d7904b8229dc859cf Mon Sep 17 00:00:00 2001 From: F1248 Date: Wed, 1 Jan 2025 20:07:15 +0100 Subject: [PATCH 01/10] Improve operators order --- Genius/Extensions/Swift/Optional.swift | 14 ++++----- Genius/Models/Operators.swift | 4 +-- .../OptionalComparisonOpearatorsTests.swift | 30 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Genius/Extensions/Swift/Optional.swift b/Genius/Extensions/Swift/Optional.swift index f4de3ee..b3199ef 100644 --- a/Genius/Extensions/Swift/Optional.swift +++ b/Genius/Extensions/Swift/Optional.swift @@ -20,21 +20,21 @@ extension Optional where Wrapped: Equatable { extension Optional where Wrapped: Comparable { - static func Bool? { - guard let lhs, let rhs else { return nil } - return lhs < rhs - } - static func >? (lhs: Self, rhs: Self) -> Bool? { guard let lhs, let rhs else { return nil } return lhs > rhs } - static func <=? (lhs: Self, rhs: Self) -> Bool? { - !?(lhs >? rhs) + static func Bool? { + guard let lhs, let rhs else { return nil } + return lhs < rhs } static func >=? (lhs: Self, rhs: Self) -> Bool? { !?(lhs Bool? { + !?(lhs >? rhs) + } } diff --git a/Genius/Models/Operators.swift b/Genius/Models/Operators.swift index 826d293..7b61c7c 100644 --- a/Genius/Models/Operators.swift +++ b/Genius/Models/Operators.swift @@ -10,9 +10,9 @@ prefix operator !? infix operator ==?: ComparisonPrecedence infix operator !=?: ComparisonPrecedence -infix operator ?: ComparisonPrecedence -infix operator <=?: ComparisonPrecedence +infix operator =?: ComparisonPrecedence +infix operator <=?: ComparisonPrecedence infix operator &&?: LogicalConjunctionPrecedence infix operator ||?: LogicalDisjunctionPrecedence diff --git a/GeniusTests/OptionalComparisonOpearatorsTests.swift b/GeniusTests/OptionalComparisonOpearatorsTests.swift index 68a32c7..e741e28 100644 --- a/GeniusTests/OptionalComparisonOpearatorsTests.swift +++ b/GeniusTests/OptionalComparisonOpearatorsTests.swift @@ -11,15 +11,6 @@ import Testing struct OptionalComparisonOpearatorsTests { - @Test - func lessThan() { - #expect((0 ? 0) == true) @@ -30,12 +21,12 @@ struct OptionalComparisonOpearatorsTests { } @Test - func lessThanOrEqualTo() { - #expect((0 <=? 1) == true) - #expect((1 <=? 0) == false) - #expect((0 <=? nil) == nil) - #expect((nil <=? 0) == nil) - #expect((nil as Int? <=? nil) == nil) + func lessThan() { + #expect((0 =? 0) == nil) #expect((nil as Int? >=? nil) == nil) } + + @Test + func lessThanOrEqualTo() { + #expect((0 <=? 1) == true) + #expect((1 <=? 0) == false) + #expect((0 <=? nil) == nil) + #expect((nil <=? 0) == nil) + #expect((nil as Int? <=? nil) == nil) + } } From d8e00ea7cc1534cf320e92e18756cfc0d4907795 Mon Sep 17 00:00:00 2001 From: F1248 Date: Thu, 2 Jan 2025 10:39:13 +0100 Subject: [PATCH 02/10] Structure tests sub-`struct`s --- .../OptionalComparisonOpearatorsTests.swift | 67 ++++++++++--------- .../OptionalEquationOpearatorsTests.swift | 31 +++++---- .../OptionalLogicalOpearatorsTests.swift | 63 ++++++++--------- GeniusTests/OptionalOpearatorsTests.swift | 9 +++ 4 files changed, 94 insertions(+), 76 deletions(-) create mode 100644 GeniusTests/OptionalOpearatorsTests.swift diff --git a/GeniusTests/OptionalComparisonOpearatorsTests.swift b/GeniusTests/OptionalComparisonOpearatorsTests.swift index e741e28..32accc0 100644 --- a/GeniusTests/OptionalComparisonOpearatorsTests.swift +++ b/GeniusTests/OptionalComparisonOpearatorsTests.swift @@ -9,41 +9,44 @@ @testable import Genius import Testing -struct OptionalComparisonOpearatorsTests { +extension OptionalOpearatorsTests { - @Test - func greaterThan() { - #expect((1 >? 0) == true) - #expect((0 >? 1) == false) - #expect((0 >? nil) == nil) - #expect((nil >? 0) == nil) - #expect((nil as Int? >? nil) == nil) - } + struct OptionalComparisonOpearatorsTests { - @Test - func lessThan() { - #expect((0 ? 0) == true) + #expect((0 >? 1) == false) + #expect((0 >? nil) == nil) + #expect((nil >? 0) == nil) + #expect((nil as Int? >? nil) == nil) + } - @Test - func greaterThanOrEqualTo() { - #expect((1 >=? 0) == true) - #expect((0 >=? 1) == false) - #expect((0 >=? nil) == nil) - #expect((nil >=? 0) == nil) - #expect((nil as Int? >=? nil) == nil) - } + @Test + func lessThan() { + #expect((0 =? 0) == true) + #expect((0 >=? 1) == false) + #expect((0 >=? nil) == nil) + #expect((nil >=? 0) == nil) + #expect((nil as Int? >=? nil) == nil) + } - @Test - func lessThanOrEqualTo() { - #expect((0 <=? 1) == true) - #expect((1 <=? 0) == false) - #expect((0 <=? nil) == nil) - #expect((nil <=? 0) == nil) - #expect((nil as Int? <=? nil) == nil) + @Test + func lessThanOrEqualTo() { + #expect((0 <=? 1) == true) + #expect((1 <=? 0) == false) + #expect((0 <=? nil) == nil) + #expect((nil <=? 0) == nil) + #expect((nil as Int? <=? nil) == nil) + } } } diff --git a/GeniusTests/OptionalEquationOpearatorsTests.swift b/GeniusTests/OptionalEquationOpearatorsTests.swift index f8c2d9a..7ffa878 100644 --- a/GeniusTests/OptionalEquationOpearatorsTests.swift +++ b/GeniusTests/OptionalEquationOpearatorsTests.swift @@ -9,21 +9,24 @@ @testable import Genius import Testing -struct OptionalEquationOpearatorsTests { +extension OptionalOpearatorsTests { - @Test - func equalTo() { - #expect((0 ==? 1) == false) - #expect((0 ==? nil) == nil) - #expect((nil ==? 0) == nil) - #expect((nil as Int? ==? nil) == nil) - } + struct OptionalEquationOpearatorsTests { + + @Test + func equalTo() { + #expect((0 ==? 1) == false) + #expect((0 ==? nil) == nil) + #expect((nil ==? 0) == nil) + #expect((nil as Int? ==? nil) == nil) + } - @Test - func notEqualTo() { - #expect((0 !=? 1) == true) - #expect((0 !=? nil) == nil) - #expect((nil !=? 0) == nil) - #expect((nil as Int? !=? nil) == nil) + @Test + func notEqualTo() { + #expect((0 !=? 1) == true) + #expect((0 !=? nil) == nil) + #expect((nil !=? 0) == nil) + #expect((nil as Int? !=? nil) == nil) + } } } diff --git a/GeniusTests/OptionalLogicalOpearatorsTests.swift b/GeniusTests/OptionalLogicalOpearatorsTests.swift index 56ce6bc..45ebc7a 100644 --- a/GeniusTests/OptionalLogicalOpearatorsTests.swift +++ b/GeniusTests/OptionalLogicalOpearatorsTests.swift @@ -9,38 +9,41 @@ @testable import Genius import Testing -struct OptionalLogicalOpearatorsTests { +extension OptionalOpearatorsTests { - @Test - func negation() { - #expect(!?true == false) - #expect(!?false == true) - #expect(!?nil == nil) - } + struct OptionalLogicalOpearatorsTests { - @Test - func conjunction() { - #expect((true &&? true) == true) - #expect((false &&? false) == false) - #expect((false &&? true) == false) - #expect((true &&? false) == false) - #expect((false &&? nil) == false) - #expect((nil &&? false) == false) - #expect((true &&? nil) == nil) - #expect((nil &&? true) == nil) - #expect((nil &&? nil) == nil) - } + @Test + func negation() { + #expect(!?true == false) + #expect(!?false == true) + #expect(!?nil == nil) + } + + @Test + func conjunction() { + #expect((true &&? true) == true) + #expect((false &&? false) == false) + #expect((false &&? true) == false) + #expect((true &&? false) == false) + #expect((false &&? nil) == false) + #expect((nil &&? false) == false) + #expect((true &&? nil) == nil) + #expect((nil &&? true) == nil) + #expect((nil &&? nil) == nil) + } - @Test - func disjunction() { - #expect((false ||? false) == false) - #expect((true ||? true) == true) - #expect((true ||? false) == true) - #expect((false ||? true) == true) - #expect((true ||? nil) == true) - #expect((nil ||? true) == true) - #expect((false ||? nil) == nil) - #expect((nil ||? false) == nil) - #expect((nil ||? nil) == nil) + @Test + func disjunction() { + #expect((false ||? false) == false) + #expect((true ||? true) == true) + #expect((true ||? false) == true) + #expect((false ||? true) == true) + #expect((true ||? nil) == true) + #expect((nil ||? true) == true) + #expect((false ||? nil) == nil) + #expect((nil ||? false) == nil) + #expect((nil ||? nil) == nil) + } } } diff --git a/GeniusTests/OptionalOpearatorsTests.swift b/GeniusTests/OptionalOpearatorsTests.swift new file mode 100644 index 0000000..84ef54c --- /dev/null +++ b/GeniusTests/OptionalOpearatorsTests.swift @@ -0,0 +1,9 @@ +// +// OptionalOpearatorsTests.swift +// GeniusTests +// +// © 2025 F1248 +// See LICENSE.txt for license information. +// + +struct OptionalOpearatorsTests {} From da5f016143dd815483bc7c6cae9ef0709f4fcf80 Mon Sep 17 00:00:00 2001 From: F1248 Date: Thu, 2 Jan 2025 10:45:41 +0100 Subject: [PATCH 03/10] Improve test function names --- GeniusTests/OptionalComparisonOpearatorsTests.swift | 8 ++++---- GeniusTests/OptionalEquationOpearatorsTests.swift | 4 ++-- GeniusTests/OptionalLogicalOpearatorsTests.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/GeniusTests/OptionalComparisonOpearatorsTests.swift b/GeniusTests/OptionalComparisonOpearatorsTests.swift index 32accc0..c0454db 100644 --- a/GeniusTests/OptionalComparisonOpearatorsTests.swift +++ b/GeniusTests/OptionalComparisonOpearatorsTests.swift @@ -14,7 +14,7 @@ extension OptionalOpearatorsTests { struct OptionalComparisonOpearatorsTests { @Test - func greaterThan() { + func optionalGreaterThan() { #expect((1 >? 0) == true) #expect((0 >? 1) == false) #expect((0 >? nil) == nil) @@ -23,7 +23,7 @@ extension OptionalOpearatorsTests { } @Test - func lessThan() { + func optionalLessThan() { #expect((0 =? 0) == true) #expect((0 >=? 1) == false) #expect((0 >=? nil) == nil) @@ -41,7 +41,7 @@ extension OptionalOpearatorsTests { } @Test - func lessThanOrEqualTo() { + func optionalLessThanOrEqualTo() { #expect((0 <=? 1) == true) #expect((1 <=? 0) == false) #expect((0 <=? nil) == nil) diff --git a/GeniusTests/OptionalEquationOpearatorsTests.swift b/GeniusTests/OptionalEquationOpearatorsTests.swift index 7ffa878..7392ec6 100644 --- a/GeniusTests/OptionalEquationOpearatorsTests.swift +++ b/GeniusTests/OptionalEquationOpearatorsTests.swift @@ -14,7 +14,7 @@ extension OptionalOpearatorsTests { struct OptionalEquationOpearatorsTests { @Test - func equalTo() { + func optionalEqualTo() { #expect((0 ==? 1) == false) #expect((0 ==? nil) == nil) #expect((nil ==? 0) == nil) @@ -22,7 +22,7 @@ extension OptionalOpearatorsTests { } @Test - func notEqualTo() { + func optionalNotEqualTo() { #expect((0 !=? 1) == true) #expect((0 !=? nil) == nil) #expect((nil !=? 0) == nil) diff --git a/GeniusTests/OptionalLogicalOpearatorsTests.swift b/GeniusTests/OptionalLogicalOpearatorsTests.swift index 45ebc7a..b3b2550 100644 --- a/GeniusTests/OptionalLogicalOpearatorsTests.swift +++ b/GeniusTests/OptionalLogicalOpearatorsTests.swift @@ -14,14 +14,14 @@ extension OptionalOpearatorsTests { struct OptionalLogicalOpearatorsTests { @Test - func negation() { + func optionalNegation() { #expect(!?true == false) #expect(!?false == true) #expect(!?nil == nil) } @Test - func conjunction() { + func optionalConjunction() { #expect((true &&? true) == true) #expect((false &&? false) == false) #expect((false &&? true) == false) @@ -34,7 +34,7 @@ extension OptionalOpearatorsTests { } @Test - func disjunction() { + func optionalDisjunction() { #expect((false ||? false) == false) #expect((true ||? true) == true) #expect((true ||? false) == true) From a0e89f7ac645398f6cc5f08cea22cbfe8b51d85a Mon Sep 17 00:00:00 2001 From: F1248 Date: Thu, 2 Jan 2025 10:50:19 +0100 Subject: [PATCH 04/10] Improve test function names --- GeniusTests/OptionalComparisonOpearatorsTests.swift | 8 ++++---- GeniusTests/OptionalEquationOpearatorsTests.swift | 4 ++-- GeniusTests/OptionalLogicalOpearatorsTests.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/GeniusTests/OptionalComparisonOpearatorsTests.swift b/GeniusTests/OptionalComparisonOpearatorsTests.swift index c0454db..cfc8cb9 100644 --- a/GeniusTests/OptionalComparisonOpearatorsTests.swift +++ b/GeniusTests/OptionalComparisonOpearatorsTests.swift @@ -14,7 +14,7 @@ extension OptionalOpearatorsTests { struct OptionalComparisonOpearatorsTests { @Test - func optionalGreaterThan() { + func optionalGreaterThanTests() { #expect((1 >? 0) == true) #expect((0 >? 1) == false) #expect((0 >? nil) == nil) @@ -23,7 +23,7 @@ extension OptionalOpearatorsTests { } @Test - func optionalLessThan() { + func optionalLessThanTests() { #expect((0 =? 0) == true) #expect((0 >=? 1) == false) #expect((0 >=? nil) == nil) @@ -41,7 +41,7 @@ extension OptionalOpearatorsTests { } @Test - func optionalLessThanOrEqualTo() { + func optionalLessThanOrEqualToTests() { #expect((0 <=? 1) == true) #expect((1 <=? 0) == false) #expect((0 <=? nil) == nil) diff --git a/GeniusTests/OptionalEquationOpearatorsTests.swift b/GeniusTests/OptionalEquationOpearatorsTests.swift index 7392ec6..1ce5284 100644 --- a/GeniusTests/OptionalEquationOpearatorsTests.swift +++ b/GeniusTests/OptionalEquationOpearatorsTests.swift @@ -14,7 +14,7 @@ extension OptionalOpearatorsTests { struct OptionalEquationOpearatorsTests { @Test - func optionalEqualTo() { + func optionalEqualToTests() { #expect((0 ==? 1) == false) #expect((0 ==? nil) == nil) #expect((nil ==? 0) == nil) @@ -22,7 +22,7 @@ extension OptionalOpearatorsTests { } @Test - func optionalNotEqualTo() { + func optionalNotEqualToTests() { #expect((0 !=? 1) == true) #expect((0 !=? nil) == nil) #expect((nil !=? 0) == nil) diff --git a/GeniusTests/OptionalLogicalOpearatorsTests.swift b/GeniusTests/OptionalLogicalOpearatorsTests.swift index b3b2550..ff52efd 100644 --- a/GeniusTests/OptionalLogicalOpearatorsTests.swift +++ b/GeniusTests/OptionalLogicalOpearatorsTests.swift @@ -14,14 +14,14 @@ extension OptionalOpearatorsTests { struct OptionalLogicalOpearatorsTests { @Test - func optionalNegation() { + func optionalNegationTests() { #expect(!?true == false) #expect(!?false == true) #expect(!?nil == nil) } @Test - func optionalConjunction() { + func optionalConjunctionTests() { #expect((true &&? true) == true) #expect((false &&? false) == false) #expect((false &&? true) == false) @@ -34,7 +34,7 @@ extension OptionalOpearatorsTests { } @Test - func optionalDisjunction() { + func optionalDisjunctionTests() { #expect((false ||? false) == false) #expect((true ||? true) == true) #expect((true ||? false) == true) From a2fae544e8a90e039382abe056903d9d893525be Mon Sep 17 00:00:00 2001 From: F1248 Date: Thu, 2 Jan 2025 10:51:18 +0100 Subject: [PATCH 05/10] Name tests and suites --- .../OptionalComparisonOpearatorsTests.swift | 9 +++++---- .../OptionalEquationOpearatorsTests.swift | 5 +++-- .../OptionalLogicalOpearatorsTests.swift | 7 ++++--- .../OptionalOpearatorsTests.swift | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) rename GeniusTests/{ => OptionalOpearatorsTests}/OptionalComparisonOpearatorsTests.swift (83%) rename GeniusTests/{ => OptionalOpearatorsTests}/OptionalEquationOpearatorsTests.swift (83%) rename GeniusTests/{ => OptionalOpearatorsTests}/OptionalLogicalOpearatorsTests.swift (87%) rename GeniusTests/{ => OptionalOpearatorsTests}/OptionalOpearatorsTests.swift (76%) diff --git a/GeniusTests/OptionalComparisonOpearatorsTests.swift b/GeniusTests/OptionalOpearatorsTests/OptionalComparisonOpearatorsTests.swift similarity index 83% rename from GeniusTests/OptionalComparisonOpearatorsTests.swift rename to GeniusTests/OptionalOpearatorsTests/OptionalComparisonOpearatorsTests.swift index cfc8cb9..bbf94f3 100644 --- a/GeniusTests/OptionalComparisonOpearatorsTests.swift +++ b/GeniusTests/OptionalOpearatorsTests/OptionalComparisonOpearatorsTests.swift @@ -11,9 +11,10 @@ import Testing extension OptionalOpearatorsTests { + @Suite("Optional comparison operators tests") struct OptionalComparisonOpearatorsTests { - @Test + @Test("Optional greater than tests") func optionalGreaterThanTests() { #expect((1 >? 0) == true) #expect((0 >? 1) == false) @@ -22,7 +23,7 @@ extension OptionalOpearatorsTests { #expect((nil as Int? >? nil) == nil) } - @Test + @Test("Optional less than tests") func optionalLessThanTests() { #expect((0 =? 0) == true) #expect((0 >=? 1) == false) @@ -40,7 +41,7 @@ extension OptionalOpearatorsTests { #expect((nil as Int? >=? nil) == nil) } - @Test + @Test("Optional less than or equal to") func optionalLessThanOrEqualToTests() { #expect((0 <=? 1) == true) #expect((1 <=? 0) == false) diff --git a/GeniusTests/OptionalEquationOpearatorsTests.swift b/GeniusTests/OptionalOpearatorsTests/OptionalEquationOpearatorsTests.swift similarity index 83% rename from GeniusTests/OptionalEquationOpearatorsTests.swift rename to GeniusTests/OptionalOpearatorsTests/OptionalEquationOpearatorsTests.swift index 1ce5284..8f7dc38 100644 --- a/GeniusTests/OptionalEquationOpearatorsTests.swift +++ b/GeniusTests/OptionalOpearatorsTests/OptionalEquationOpearatorsTests.swift @@ -11,9 +11,10 @@ import Testing extension OptionalOpearatorsTests { + @Suite("Optional equation operators tests") struct OptionalEquationOpearatorsTests { - @Test + @Test("Optional equal to tests") func optionalEqualToTests() { #expect((0 ==? 1) == false) #expect((0 ==? nil) == nil) @@ -21,7 +22,7 @@ extension OptionalOpearatorsTests { #expect((nil as Int? ==? nil) == nil) } - @Test + @Test("Optional not equal to tests") func optionalNotEqualToTests() { #expect((0 !=? 1) == true) #expect((0 !=? nil) == nil) diff --git a/GeniusTests/OptionalLogicalOpearatorsTests.swift b/GeniusTests/OptionalOpearatorsTests/OptionalLogicalOpearatorsTests.swift similarity index 87% rename from GeniusTests/OptionalLogicalOpearatorsTests.swift rename to GeniusTests/OptionalOpearatorsTests/OptionalLogicalOpearatorsTests.swift index ff52efd..e98ed91 100644 --- a/GeniusTests/OptionalLogicalOpearatorsTests.swift +++ b/GeniusTests/OptionalOpearatorsTests/OptionalLogicalOpearatorsTests.swift @@ -11,16 +11,17 @@ import Testing extension OptionalOpearatorsTests { + @Suite("Optional logical operators tests") struct OptionalLogicalOpearatorsTests { - @Test + @Test("Optional negation tests") func optionalNegationTests() { #expect(!?true == false) #expect(!?false == true) #expect(!?nil == nil) } - @Test + @Test("Optional conjunction tests") func optionalConjunctionTests() { #expect((true &&? true) == true) #expect((false &&? false) == false) @@ -33,7 +34,7 @@ extension OptionalOpearatorsTests { #expect((nil &&? nil) == nil) } - @Test + @Test("Optional disjunction tests") func optionalDisjunctionTests() { #expect((false ||? false) == false) #expect((true ||? true) == true) diff --git a/GeniusTests/OptionalOpearatorsTests.swift b/GeniusTests/OptionalOpearatorsTests/OptionalOpearatorsTests.swift similarity index 76% rename from GeniusTests/OptionalOpearatorsTests.swift rename to GeniusTests/OptionalOpearatorsTests/OptionalOpearatorsTests.swift index 84ef54c..c61b517 100644 --- a/GeniusTests/OptionalOpearatorsTests.swift +++ b/GeniusTests/OptionalOpearatorsTests/OptionalOpearatorsTests.swift @@ -6,4 +6,7 @@ // See LICENSE.txt for license information. // +import Testing + +@Suite("Optional opearators tests") struct OptionalOpearatorsTests {} From ffd404a0e8b3cc7c753185fef5d13ca59045acbd Mon Sep 17 00:00:00 2001 From: F1248 Date: Sun, 5 Jan 2025 13:26:23 +0100 Subject: [PATCH 06/10] Use property wrapper `Default` instead of `AppStorage` --- Genius/Views/Common/VaryingText.swift | 5 ++--- Genius/Views/Settings/SettingsView.swift | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Genius/Views/Common/VaryingText.swift b/Genius/Views/Common/VaryingText.swift index 289b365..69e6e7d 100644 --- a/Genius/Views/Common/VaryingText.swift +++ b/Genius/Views/Common/VaryingText.swift @@ -7,13 +7,12 @@ // import Defaults -import SwiftUI import SwiftUICore struct VaryingText: View { - @AppStorage(Defaults.Keys.interfaceMode.name) - var interfaceMode: Settings.InterfaceMode = Defaults.Keys.interfaceMode.defaultValue + @Default(.interfaceMode) + var interfaceMode: Settings.InterfaceMode let key: LocalizedStringKey diff --git a/Genius/Views/Settings/SettingsView.swift b/Genius/Views/Settings/SettingsView.swift index 927afeb..25d705d 100644 --- a/Genius/Views/Settings/SettingsView.swift +++ b/Genius/Views/Settings/SettingsView.swift @@ -12,10 +12,10 @@ import SwiftUICore struct SettingsView: View { - @AppStorage(Defaults.Keys.interfaceMode.name) - var interfaceMode: Settings.InterfaceMode = Defaults.Keys.interfaceMode.defaultValue - @AppStorage(Defaults.Keys.developmentMode.name) - var developmentMode: Bool = Defaults.Keys.developmentMode.defaultValue + @Default(.interfaceMode) + var interfaceMode: Settings.InterfaceMode + @Default(.developmentMode) + var developmentMode: Bool var body: some View { Text("Settings") From c267dc2c747d70f7de0cc9f37d308c82a37aabb1 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 6 Jan 2025 16:37:37 +0100 Subject: [PATCH 07/10] Improve code style --- Genius/ViewModels/Tabs/CustomTabContentBuilder.swift | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Genius/ViewModels/Tabs/CustomTabContentBuilder.swift b/Genius/ViewModels/Tabs/CustomTabContentBuilder.swift index 366a893..15b73b9 100644 --- a/Genius/ViewModels/Tabs/CustomTabContentBuilder.swift +++ b/Genius/ViewModels/Tabs/CustomTabContentBuilder.swift @@ -9,11 +9,6 @@ @resultBuilder enum CustomTabContentBuilder { - static func buildBlock(_ tabs: [CustomTab]) -> [CustomTab] { - tabs - } - - static func buildBlock(_ tabs: CustomTab...) -> [CustomTab] { - tabs - } + static func buildBlock(_ tabs: [CustomTab]) -> [CustomTab] { tabs } + static func buildBlock(_ tabs: CustomTab...) -> [CustomTab] { tabs } } From 5a7cccae328e68405a0fa37add877fb226b67016 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 6 Jan 2025 20:27:25 +0100 Subject: [PATCH 08/10] Trim whitespaces and newlines when reading pipes --- Genius/Extensions/Foundation/Pipe.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Genius/Extensions/Foundation/Pipe.swift b/Genius/Extensions/Foundation/Pipe.swift index acaaca0..ce439ab 100644 --- a/Genius/Extensions/Foundation/Pipe.swift +++ b/Genius/Extensions/Foundation/Pipe.swift @@ -11,6 +11,6 @@ import Foundation extension Pipe { func read() -> String? { - try? String(fileHandleForReading.readToEnd()) + try? String(fileHandleForReading.readToEnd())?.trimmingCharacters(in: .whitespacesAndNewlines) } } From dc18771c564c0e849b662e1f4418b45d67a770b0 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 6 Jan 2025 21:36:43 +0100 Subject: [PATCH 09/10] Add attribute `autoclosure` to parameter `value` of initializer of struct `SystemInformationData` --- .../Models/SystemInformation/Hardware.swift | 12 +++++----- .../SystemInformation/MaintenanceChecks.swift | 22 +++++++++---------- .../Models/SystemInformation/Software.swift | 12 +++++----- .../SystemInformationData.swift | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Genius/Models/SystemInformation/Hardware.swift b/Genius/Models/SystemInformation/Hardware.swift index b5fab12..bd8a1c8 100644 --- a/Genius/Models/SystemInformation/Hardware.swift +++ b/Genius/Models/SystemInformation/Hardware.swift @@ -35,11 +35,11 @@ extension SystemInformation { let regionInfo = IORegistry(class: "IOPlatformExpertDevice").read("region-info") as String? else { return nil } return modelNumber + regionInfo - }, + }(), applicable: CPU.type.value == .appleSilicon ) static let regulatoryNumber = SystemInformationData( - { IORegistry(class: "IOPlatformExpertDevice").read("regulatory-model-number") }, + IORegistry(class: "IOPlatformExpertDevice").read("regulatory-model-number"), applicable: CPU.type.value == .appleSilicon &&? !?isVirtualMachine.value ) // periphery:ignore @@ -91,9 +91,9 @@ extension SystemInformation { static let differentTypes = SystemInformationData(type.value == .appleSilicon &&? !?Model.isVirtualMachine.value) static let total = SystemInformationData(Sysctl.read("hw.physicalcpu")) static let performance = - SystemInformationData({ Sysctl.read("hw.perflevel0.physicalcpu") }, applicable: differentTypes.value) + SystemInformationData(Sysctl.read("hw.perflevel0.physicalcpu"), applicable: differentTypes.value) static let efficiency = - SystemInformationData({ Sysctl.read("hw.perflevel1.physicalcpu") }, applicable: differentTypes.value) + SystemInformationData(Sysctl.read("hw.perflevel1.physicalcpu"), applicable: differentTypes.value) } static let type = SystemInformationData({ @@ -107,7 +107,7 @@ extension SystemInformation { }()) static let name = SystemInformationData(Sysctl.read("machdep.cpu.brand_string")) static let frequency = - SystemInformationData({ Sysctl.read("hw.cpufrequency").map(Frequency.init) }, applicable: type.value == .intel) + SystemInformationData(Sysctl.read("hw.cpufrequency").map(Frequency.init), applicable: type.value == .intel) } static let memory = SystemInformationData(Sysctl.read("hw.memsize").map(InformationStorage.init)) @@ -119,7 +119,7 @@ extension SystemInformation { static let hardwareUUID = SystemInformationData(IORegistry(class: "IOPlatformExpertDevice").read(kIOPlatformUUIDKey)) static let provisioningUDID = SystemInformationData( - { SystemProfiler.hardware?["provisioning_UDID"] as? String ?? (CPU.type.value == .intel ? hardwareUUID.value : nil) }, + SystemProfiler.hardware?["provisioning_UDID"] as? String ?? (CPU.type.value == .intel ? hardwareUUID.value : nil), applicable: Software.OS.bootMode.value !=? .recovery ||? CPU.type.value == .intel ) } diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index a61fcc7..e2f305d 100644 --- a/Genius/Models/SystemInformation/MaintenanceChecks.swift +++ b/Genius/Models/SystemInformation/MaintenanceChecks.swift @@ -15,11 +15,11 @@ extension SystemInformation { enum TheftProtection { static let activationLock = SystemInformationData( - { IORegistry(class: "IODTNVRAMVariables").keyExists("fmm-mobileme-token-FMM") }, + IORegistry(class: "IODTNVRAMVariables").keyExists("fmm-mobileme-token-FMM"), applicable: Hardware.securityChip.value >=? .t2 &&? !?Hardware.Model.isVirtualMachine.value ) static let firmwarePassword = SystemInformationData( - { Bool(Process("/usr/sbin/firmwarepasswd", ["-check"], requiresRoot: true)?.runSafe()) }, + Bool(Process("/usr/sbin/firmwarepasswd", ["-check"], requiresRoot: true)?.runSafe()), applicable: Hardware.CPU.type.value == .intel &&? !?Hardware.Model.isVirtualMachine.value ) } @@ -27,7 +27,7 @@ extension SystemInformation { enum DataSecurity { static let fileVault = SystemInformationData( - { Bool(Process("/usr/bin/fdesetup", ["status"])?.runSafe()) }, + Bool(Process("/usr/bin/fdesetup", ["status"])?.runSafe()), applicable: Software.OS.bootMode.value !=? .recovery ) } @@ -35,11 +35,11 @@ extension SystemInformation { enum MalwareProtection { static let systemIntegrityProtection = SystemInformationData( - { Bool(Process("/usr/bin/csrutil", ["status"])?.runSafe()) }, + Bool(Process("/usr/bin/csrutil", ["status"])?.runSafe()), applicable: Software.OS.bootMode.value !=? .recovery ) static let firewall = SystemInformationData( - { Bool(Process("/usr/libexec/ApplicationFirewall/socketfilterfw", ["--getglobalstate"])?.runSafe()) }, + Bool(Process("/usr/libexec/ApplicationFirewall/socketfilterfw", ["--getglobalstate"])?.runSafe()), applicable: Software.OS.bootMode.value !=? .recovery ) static let gatekeeper = SystemInformationData(Bool(Process("/usr/sbin/spctl", ["--status"])?.runSafe())) @@ -48,27 +48,27 @@ extension SystemInformation { enum AutomaticUpdates { static let checkMacOS = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticCheckEnabled") }, + UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticCheckEnabled"), applicable: { if #unavailable(macOS 15) { true } else { false } }() &&? Software.OS.bootMode.value !=? .recovery ) static let downloadMacOS = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticDownload") }, + UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticDownload"), applicable: Software.OS.bootMode.value !=? .recovery ) static let installMacOS = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticallyInstallMacOSUpdates") }, + UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "AutomaticallyInstallMacOSUpdates"), applicable: Software.OS.bootMode.value !=? .recovery ) static let installCritical = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "CriticalUpdateInstall") }, + UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "CriticalUpdateInstall"), applicable: Software.OS.bootMode.value !=? .recovery ) static let installConfigurationData = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "ConfigDataInstall") }, + UserDefaults.read("/Library/Preferences/com.apple.SoftwareUpdate", "ConfigDataInstall"), applicable: Software.OS.bootMode.value !=? .recovery ) static let installAppStoreApps = SystemInformationData( - { UserDefaults.read("/Library/Preferences/com.apple.commerce", "AutoUpdate") }, + UserDefaults.read("/Library/Preferences/com.apple.commerce", "AutoUpdate"), applicable: Software.OS.bootMode.value !=? .recovery ) } diff --git a/Genius/Models/SystemInformation/Software.swift b/Genius/Models/SystemInformation/Software.swift index f512409..d68186b 100644 --- a/Genius/Models/SystemInformation/Software.swift +++ b/Genius/Models/SystemInformation/Software.swift @@ -16,7 +16,7 @@ extension SystemInformation { enum SMC { static let version = SystemInformationData( - { SystemProfiler.hardware?["SMC_version_system"] as? String }, + SystemProfiler.hardware?["SMC_version_system"] as? String, applicable: Hardware.securityChip.value <=? .t1 &&? OS.bootMode.value !=? .recovery ) } @@ -24,7 +24,7 @@ extension SystemInformation { enum Firmware { static let version = SystemInformationData( - { SystemProfiler.hardware?["boot_rom_version"] as? String }, + SystemProfiler.hardware?["boot_rom_version"] as? String, applicable: OS.bootMode.value !=? .recovery ) } @@ -61,12 +61,10 @@ extension SystemInformation { safe ? .safe : .normal } else { nil } }()) - static let bootVolume = SystemInformationData( - { SystemProfiler.software?["boot_volume"] as? String }, - applicable: bootMode.value !=? .recovery - ) + static let bootVolume = + SystemInformationData(SystemProfiler.software?["boot_volume"] as? String, applicable: bootMode.value !=? .recovery) static let loaderVersion = SystemInformationData( - { SystemProfiler.hardware?["os_loader_version"] as? String }, + SystemProfiler.hardware?["os_loader_version"] as? String, applicable: bootMode.value !=? .recovery ) } diff --git a/Genius/Models/SystemInformation/SystemInformationData.swift b/Genius/Models/SystemInformation/SystemInformationData.swift index 46bc1f4..efbee76 100644 --- a/Genius/Models/SystemInformation/SystemInformationData.swift +++ b/Genius/Models/SystemInformation/SystemInformationData.swift @@ -16,7 +16,7 @@ struct SystemInformationData: SystemInformationDataProtocol { self.applicable = true } - init(_ value: () -> T, applicable: Bool?) where T == W? { + init(_ value: @autoclosure () -> T, applicable: Bool?) where T == W? { self.value = applicable ?? true ? value() : nil self.applicable = applicable } From 836d04b922c8761f31699e769e27939df4fb9ea9 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 6 Jan 2025 22:12:34 +0100 Subject: [PATCH 10/10] Improve performance by making parameter `rhs` of optional logical operators `Bool` a autoclosure --- Genius/Extensions/Swift/Bool.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index c898e11..8a1db5d 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -46,19 +46,19 @@ extension Bool? { bool.map(!) } - static func &&? (lhs: Self, rhs: Self) -> Self { - if let lhs, let rhs { - lhs && rhs - } else if [lhs, rhs].contains(false) { - false - } else { nil } + static func &&? (lhs: Self, rhs: @autoclosure () -> Self) -> Self { + switch lhs { + case true: rhs() + case false: false + default: rhs() == false ? false : nil + } } - static func ||? (lhs: Self, rhs: Self) -> Self { - if let lhs, let rhs { - lhs || rhs - } else if [lhs, rhs].contains(true) { - true - } else { nil } + static func ||? (lhs: Self, rhs: @autoclosure () -> Self) -> Self { + switch lhs { + case true: true + case false: rhs() + default: rhs() == true ? true : nil + } } }