diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 000000000..690f0afdd --- /dev/null +++ b/.swiftformat @@ -0,0 +1,17 @@ +--swiftversion 5.6 + +--exclude ElementX/Sources/Generated + +--disable wrapMultiLineStatementBraces +--disable blankLinesAtStartOfScope +--disable blankLinesAtEndOfScope +--disable hoistPatternLet + +--commas inline +--ifdef no-indent +--nospaceoperators ...,..< +--stripunusedargs closure-only +--trimwhitespace nonblank-lines +--wrapparameters after-first +--redundanttype inferred +--emptybraces spaced \ No newline at end of file diff --git a/Dangerfile.swift b/Dangerfile.swift index f0ff6bc9f..9b118bd69 100644 --- a/Dangerfile.swift +++ b/Dangerfile.swift @@ -1,5 +1,5 @@ -import Foundation import Danger +import Foundation SwiftLint.lint(inline: true) @@ -19,7 +19,7 @@ if danger.github.pullRequest.body?.isEmpty ?? true { let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles let changelogFiles = editedFiles.filter { $0.hasPrefix("changelog.d/") } -if editedFiles.count > 0 && changelogFiles.isEmpty { +if editedFiles.count > 0, changelogFiles.isEmpty { warn("Please add a changelog.") } @@ -27,7 +27,7 @@ if editedFiles.count > 0 && changelogFiles.isEmpty { if let ticketNumberRegex = try? NSRegularExpression(pattern: "#\\d+") { let missingTicketNumber = !danger.git.commits.filter { !$0.message.contains("vector-im/element-x-ios/issues/") && - ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil + ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil }.isEmpty if missingTicketNumber { @@ -63,7 +63,7 @@ if requiresSignOff { !$0.message.contains(signOff) }.isEmpty - if !hasPRBodySignOff && isMissingCommitsSignOff { + if !hasPRBodySignOff, isMissingCommitsSignOff { fail("Please add a sign-off to either the PR description or to the commits themselves.") } } diff --git a/DesignKit/Sources/Buttons/ElementActionButtonStyle.swift b/DesignKit/Sources/Buttons/ElementActionButtonStyle.swift index 5f61cd6f3..15a68c959 100644 --- a/DesignKit/Sources/Buttons/ElementActionButtonStyle.swift +++ b/DesignKit/Sources/Buttons/ElementActionButtonStyle.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import DesignTokens +import SwiftUI public extension ButtonStyle where Self == ElementActionButtonStyle { /// The CTA button style as defined in Compound. @@ -70,17 +70,17 @@ public struct ElementActionButtonStyle_Previews: PreviewProvider { Button("Enabled") { /* preview */ } .buttonStyle(ElementActionButtonStyle()) - Button("Disabled") { /* preview */ } + Button("Disabled") { /* preview */ } .buttonStyle(ElementActionButtonStyle()) .disabled(true) - Button { /* preview */ } label: { + Button { /* preview */ } label: { Text("Clear BG") .foregroundColor(.element.alert) } .buttonStyle(ElementActionButtonStyle(color: .clear)) - Button("Red BG") { /* preview */ } + Button("Red BG") { /* preview */ } .buttonStyle(ElementActionButtonStyle(color: .element.alert)) } .padding() diff --git a/DesignKit/Sources/Buttons/ElementGhostButtonStyle.swift b/DesignKit/Sources/Buttons/ElementGhostButtonStyle.swift index 86f8ad1db..0740b5483 100644 --- a/DesignKit/Sources/Buttons/ElementGhostButtonStyle.swift +++ b/DesignKit/Sources/Buttons/ElementGhostButtonStyle.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import DesignTokens +import SwiftUI public extension ButtonStyle where Self == ElementGhostButtonStyle { /// The Ghost button style as defined in Compound. diff --git a/DesignKit/Sources/Fonts/ElementSharedFonts.swift b/DesignKit/Sources/Fonts/ElementSharedFonts.swift index 2fb05db2f..8090132c9 100644 --- a/DesignKit/Sources/Fonts/ElementSharedFonts.swift +++ b/DesignKit/Sources/Fonts/ElementSharedFonts.swift @@ -35,110 +35,111 @@ public class ElementSharedFonts { /// Returns an instance of the font associated with the text style and scaled appropriately for the content size category defined in the trait collection. /// Keep this method private method at the moment and create a DesignKit.Fonts.TextStyle if needed. - fileprivate func font(forTextStyle textStyle: UIFont.TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont { - return UIFont.preferredFont(forTextStyle: textStyle, compatibleWith: traitCollection) + private func font(forTextStyle textStyle: UIFont.TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont { + UIFont.preferredFont(forTextStyle: textStyle, compatibleWith: traitCollection) } } // MARK: - Fonts protocol -extension ElementSharedFonts { + +public extension ElementSharedFonts { - public var largeTitle: SharedFont { + var largeTitle: SharedFont { let uiFont = font(forTextStyle: .largeTitle) return SharedFont(uiFont: uiFont, font: .largeTitle) } - public var largeTitleB: SharedFont { + var largeTitleB: SharedFont { let uiFont = largeTitle.uiFont.bold return SharedFont(uiFont: uiFont, font: .largeTitle.bold()) } - public var title1: SharedFont { + var title1: SharedFont { let uiFont = font(forTextStyle: .title1) return SharedFont(uiFont: uiFont, font: .title) } - public var title1B: SharedFont { + var title1B: SharedFont { let uiFont = title1.uiFont.bold return SharedFont(uiFont: uiFont, font: .title.bold()) } - public var title2: SharedFont { + var title2: SharedFont { let uiFont = font(forTextStyle: .title2) return SharedFont(uiFont: uiFont, font: .title2) } - public var title2B: SharedFont { + var title2B: SharedFont { let uiFont = title2.uiFont.bold return SharedFont(uiFont: uiFont, font: .title2.bold()) } - public var title3: SharedFont { + var title3: SharedFont { let uiFont = font(forTextStyle: .title3) return SharedFont(uiFont: uiFont, font: .title3) } - public var title3SB: SharedFont { + var title3SB: SharedFont { let uiFont = title3.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .title3.weight(.semibold)) } - public var headline: SharedFont { + var headline: SharedFont { let uiFont = font(forTextStyle: .headline) return SharedFont(uiFont: uiFont, font: .headline) } - public var subheadline: SharedFont { + var subheadline: SharedFont { let uiFont = font(forTextStyle: .subheadline) return SharedFont(uiFont: uiFont, font: .subheadline) } - public var body: SharedFont { + var body: SharedFont { let uiFont = font(forTextStyle: .body) return SharedFont(uiFont: uiFont, font: .body) } - public var bodySB: SharedFont { + var bodySB: SharedFont { let uiFont = body.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .body.weight(.semibold)) } - public var callout: SharedFont { + var callout: SharedFont { let uiFont = font(forTextStyle: .callout) return SharedFont(uiFont: uiFont, font: .callout) } - public var calloutSB: SharedFont { + var calloutSB: SharedFont { let uiFont = callout.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .callout.weight(.semibold)) } - public var footnote: SharedFont { + var footnote: SharedFont { let uiFont = font(forTextStyle: .footnote) return SharedFont(uiFont: uiFont, font: .footnote) } - public var footnoteSB: SharedFont { + var footnoteSB: SharedFont { let uiFont = footnote.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .footnote.weight(.semibold)) } - public var caption1: SharedFont { + var caption1: SharedFont { let uiFont = font(forTextStyle: .caption1) return SharedFont(uiFont: uiFont, font: .caption) } - public var caption1SB: SharedFont { + var caption1SB: SharedFont { let uiFont = caption1.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .caption.weight(.semibold)) } - public var caption2: SharedFont { + var caption2: SharedFont { let uiFont = font(forTextStyle: .caption2) return SharedFont(uiFont: uiFont, font: .caption2) } - public var caption2SB: SharedFont { + var caption2SB: SharedFont { let uiFont = caption2.uiFont.semiBold return SharedFont(uiFont: uiFont, font: .caption2.weight(.semibold)) } diff --git a/DesignKit/Sources/Fonts/UIFont.swift b/DesignKit/Sources/Fonts/UIFont.swift index 7d8ad6d77..f1524ca6e 100644 --- a/DesignKit/Sources/Fonts/UIFont.swift +++ b/DesignKit/Sources/Fonts/UIFont.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,14 +44,14 @@ public extension UIFont { // MARK: - Shortcuts var bold: UIFont { - return withTraits(.traitBold) + withTraits(.traitBold) } var semiBold: UIFont { - return withWeight(weight: .semibold) + withWeight(weight: .semibold) } var italic: UIFont { - return withTraits(.traitItalic) + withTraits(.traitItalic) } } diff --git a/DesignKit/Sources/Shapes/RoundedCornerShape.swift b/DesignKit/Sources/Shapes/RoundedCornerShape.swift index ab38895eb..9fea65fe9 100644 --- a/DesignKit/Sources/Shapes/RoundedCornerShape.swift +++ b/DesignKit/Sources/Shapes/RoundedCornerShape.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift b/DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift index 9ca38c65c..0f5630fa8 100644 --- a/DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift +++ b/DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,9 @@ // limitations under the License. // -import SwiftUI import DesignTokens import Introspect +import SwiftUI /// A bordered style of text input /// @@ -48,7 +48,7 @@ public struct BorderedInputFieldStyle: TextFieldStyle { } private var backgroundColor: Color { - if !isEnabled && colorScheme == .dark { + if !isEnabled, colorScheme == .dark { return .element.quinaryContent } return .element.background diff --git a/DesignKit/Sources/TextFields/ElementTextFieldStyle.swift b/DesignKit/Sources/TextFields/ElementTextFieldStyle.swift index f1d158892..73db8dc04 100644 --- a/DesignKit/Sources/TextFields/ElementTextFieldStyle.swift +++ b/DesignKit/Sources/TextFields/ElementTextFieldStyle.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import DesignTokens +import SwiftUI @available(iOS 15.0, *) public extension TextFieldStyle where Self == ElementTextFieldStyle { diff --git a/DesignKitTests/DesignKitTests.swift b/DesignKitTests/DesignKitTests.swift index a38bdac68..d2f41381c 100644 --- a/DesignKitTests/DesignKitTests.swift +++ b/DesignKitTests/DesignKitTests.swift @@ -1,5 +1,5 @@ -import XCTest @testable import DesignKit +import XCTest final class DesignKitTests: XCTestCase { func testExample() throws { diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index d9efd3d80..2dce3378a 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -130,6 +130,7 @@ 62BBF5BE7B905222F0477FF2 /* MediaSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8210612D17A39369480FC183 /* MediaSource.swift */; }; 63C9AF0FB8278AF1C0388A0C /* TemplateModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB10E673916D2B8D21FD197 /* TemplateModels.swift */; }; 6647430A45B4A8E692909A8F /* EmoteRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77C060C2ACC4CB7336A29E7 /* EmoteRoomTimelineItem.swift */; }; + 67C05C50AD734283374605E3 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */; }; 67E391A2E00709FB41903B36 /* MockMediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6920A4869821BF72FFC58842 /* MockMediaProvider.swift */; }; 6832733838C57A7D3FE8FEB5 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 04C28663564E008DB32B5972 /* Introspect */; }; 684BDE198AE5AA1392288A73 /* SplashScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32CE6D4FF64C9A3C18619224 /* SplashScreen.swift */; }; @@ -279,7 +280,6 @@ EE8491AD81F47DF3C192497B /* DecorationTimelineItemProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CF8C196BE143AE226628D /* DecorationTimelineItemProtocol.swift */; }; EEC40663922856C65D1E0DF5 /* KeychainControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB9C37196A4C79F24CE80C6 /* KeychainControllerTests.swift */; }; EF99A92701E401C4CD5ADC50 /* SplashScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE978A6118C131D7F2A04B3 /* SplashScreenModels.swift */; }; - F03E16ED043C62FED5A07AE0 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */; }; F040ABFEB0A2B142D948BA12 /* Untranslated.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = F75DF9500D69A3AAF8339E69 /* Untranslated.stringsdict */; }; F2DD8661B5C0BA2BB526FA6C /* KeychainControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CD51F9FDC91C231906D76C8 /* KeychainControllerProtocol.swift */; }; F4C3FEDB1B3A05376A1723A3 /* KeychainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A4427F9E0571B4E6E048A2B /* KeychainController.swift */; }; @@ -479,6 +479,7 @@ 6920A4869821BF72FFC58842 /* MockMediaProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMediaProvider.swift; sourceTree = ""; }; 6A152791A2F56BD193BFE986 /* MemberDetailsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberDetailsProvider.swift; sourceTree = ""; }; 6A901D95158B02CA96C79C7F /* InfoPlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoPlist.swift; sourceTree = ""; }; + 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixEntityRegex.swift; sourceTree = ""; }; 6B73A8C3118EAC7BF3F3EE7A /* SplashScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashScreenViewModelProtocol.swift; sourceTree = ""; }; 6D4777F0142E330A75C46FE4 /* SessionVerificationUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationUITests.swift; sourceTree = ""; }; 6DB53055CB130F0651C70763 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = ""; }; @@ -691,7 +692,6 @@ F6A8C632CEF4600107792899 /* TextRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineItem.swift; sourceTree = ""; }; F73FF1A33198F5FAE9D34B1F /* FormattedBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormattedBodyText.swift; sourceTree = ""; }; F77C060C2ACC4CB7336A29E7 /* EmoteRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomTimelineItem.swift; sourceTree = ""; }; - F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixEntityRegex.swift; sourceTree = ""; }; F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineView.swift; sourceTree = ""; }; FA154570F693D93513E584C1 /* RoomMessageFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMessageFactory.swift; sourceTree = ""; }; FAB10E673916D2B8D21FD197 /* TemplateModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateModels.swift; sourceTree = ""; }; @@ -1443,7 +1443,7 @@ CF4B39D52CAE7D21D276ABEE /* ElementNavigationController.swift */, 1027BB9A852F445B7623897F /* ElementSettings.swift */, 12A626D74BBE9F4A60763B45 /* ImageAnonymizer.swift */, - F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */, + 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */, 44BBB96FAA2F0D53C507396B /* Extensions */, 8F9A844EB44B6AD7CA18FD96 /* HTMLParsing */, 06501F0E978B2D5C92771DC7 /* Logging */, @@ -1659,6 +1659,7 @@ isa = PBXNativeTarget; buildConfigurationList = B15427F8699AD5A5FC75C17E /* Build configuration list for PBXNativeTarget "ElementX" */; buildPhases = ( + B35AB66424BB30087EEE408C /* 🧹 SwiftFormat */, A7130911BCB2DF3D249A1836 /* 🛠 SwiftGen */, 9797D588420FCBBC228A63C9 /* Sources */, 215E1D91B98672C856F559D0 /* Resources */, @@ -1886,6 +1887,24 @@ shellPath = /bin/sh; shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftgen >/dev/null; then\n swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml\nelse\n echo \"warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen\"\nfi\n"; }; + B35AB66424BB30087EEE408C /* 🧹 SwiftFormat */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "🧹 SwiftFormat"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftformat >/dev/null; then\n swiftformat $PROJECT_DIR\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -1997,7 +2016,7 @@ 2F30EFEB7BD39242D1AD96F3 /* LoginViewModelProtocol.swift in Sources */, B94368839BDB69172E28E245 /* MXLog.swift in Sources */, BCC3EDB7AD0902797CB4BBC2 /* MXLogger.m in Sources */, - F03E16ED043C62FED5A07AE0 /* MatrixEntityRegex.swift in Sources */, + 67C05C50AD734283374605E3 /* MatrixEntityRegex.swift in Sources */, EA1E7949533E19C6D862680A /* MediaProvider.swift in Sources */, 7002C55A4C917F3715765127 /* MediaProviderProtocol.swift in Sources */, 62BBF5BE7B905222F0477FF2 /* MediaSource.swift in Sources */, diff --git a/ElementX/Sources/AppCoordinator.swift b/ElementX/Sources/AppCoordinator.swift index 0e3ce5da6..790c0559b 100644 --- a/ElementX/Sources/AppCoordinator.swift +++ b/ElementX/Sources/AppCoordinator.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Combine +import UIKit class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator { private let window: UIWindow @@ -149,6 +149,7 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator { fatalError("Failed transition with context: \(context)") } } + // swiftlint:enable cyclomatic_complexity function_body_length private func restoreUserSession() { diff --git a/ElementX/Sources/AppCoordinatorStateMachine.swift b/ElementX/Sources/AppCoordinatorStateMachine.swift index 837421e97..cb37a7051 100644 --- a/ElementX/Sources/AppCoordinatorStateMachine.swift +++ b/ElementX/Sources/AppCoordinatorStateMachine.swift @@ -77,23 +77,23 @@ class AppCoordinatorStateMachine { init() { stateMachine = StateMachine(state: .initial) { machine in - machine.addRoutes(event: .startWithAuthentication, transitions: [ .initial => .signedOut ]) - machine.addRoutes(event: .succeededSigningIn, transitions: [ .signedOut => .homeScreen ]) + machine.addRoutes(event: .startWithAuthentication, transitions: [.initial => .signedOut]) + machine.addRoutes(event: .succeededSigningIn, transitions: [.signedOut => .homeScreen]) - machine.addRoutes(event: .startWithExistingSession, transitions: [ .initial => .restoringSession ]) - machine.addRoutes(event: .succeededRestoringSession, transitions: [ .restoringSession => .homeScreen ]) - machine.addRoutes(event: .failedRestoringSession, transitions: [ .restoringSession => .signedOut ]) + machine.addRoutes(event: .startWithExistingSession, transitions: [.initial => .restoringSession]) + machine.addRoutes(event: .succeededRestoringSession, transitions: [.restoringSession => .homeScreen]) + machine.addRoutes(event: .failedRestoringSession, transitions: [.restoringSession => .signedOut]) - machine.addRoutes(event: .attemptSignOut, transitions: [ .settingsScreen => .signingOut ]) + machine.addRoutes(event: .attemptSignOut, transitions: [.settingsScreen => .signingOut]) - machine.addRoutes(event: .succeededSigningOut, transitions: [ .signingOut => .signedOut ]) - machine.addRoutes(event: .failedSigningOut, transitions: [ .signingOut => .settingsScreen ]) + machine.addRoutes(event: .succeededSigningOut, transitions: [.signingOut => .signedOut]) + machine.addRoutes(event: .failedSigningOut, transitions: [.signingOut => .settingsScreen]) - machine.addRoutes(event: .showSettingsScreen, transitions: [ .homeScreen => .settingsScreen ]) - machine.addRoutes(event: .dismissedSettingsScreen, transitions: [ .settingsScreen => .homeScreen ]) + machine.addRoutes(event: .showSettingsScreen, transitions: [.homeScreen => .settingsScreen]) + machine.addRoutes(event: .dismissedSettingsScreen, transitions: [.settingsScreen => .homeScreen]) - machine.addRoutes(event: .showSessionVerificationScreen, transitions: [ .homeScreen => .sessionVerificationScreen ]) - machine.addRoutes(event: .dismissedSessionVerificationScreen, transitions: [ .sessionVerificationScreen => .homeScreen ]) + machine.addRoutes(event: .showSessionVerificationScreen, transitions: [.homeScreen => .sessionVerificationScreen]) + machine.addRoutes(event: .dismissedSessionVerificationScreen, transitions: [.sessionVerificationScreen => .homeScreen]) // Transitions with associated values need to be handled through `addRouteMapping` machine.addRouteMapping { event, fromState, _ in diff --git a/ElementX/Sources/AppDelegate.swift b/ElementX/Sources/AppDelegate.swift index b425c6830..deb5a226c 100644 --- a/ElementX/Sources/AppDelegate.swift +++ b/ElementX/Sources/AppDelegate.swift @@ -14,8 +14,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { private lazy var appCoordinator: Coordinator = isRunningUITests ? UITestsAppCoordinator() : AppCoordinator() func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { - - // fixme: Use `Bundle.elementLanguage = ".."` when we have the functionality // use `en` as fallback language Bundle.elementFallbackLanguage = "en" @@ -34,17 +32,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate { private var isRunningUnitTests: Bool { #if DEBUG - ProcessInfo.processInfo.environment["IS_RUNNING_UNIT_TESTS"] == "1" + ProcessInfo.processInfo.environment["IS_RUNNING_UNIT_TESTS"] == "1" #else - false + false #endif } private var isRunningUITests: Bool { #if DEBUG - ProcessInfo.processInfo.environment["IS_RUNNING_UI_TESTS"] == "1" + ProcessInfo.processInfo.environment["IS_RUNNING_UI_TESTS"] == "1" #else - false + false #endif } } diff --git a/ElementX/Sources/BuildSettings.swift b/ElementX/Sources/BuildSettings.swift index c4a88a961..d3ec391a0 100644 --- a/ElementX/Sources/BuildSettings.swift +++ b/ElementX/Sources/BuildSettings.swift @@ -11,22 +11,26 @@ import Foundation final class BuildSettings { // MARK: - Servers + static let defaultHomeserverURLString = "https://matrix.org" // MARK: - Bug report + static let bugReportServiceBaseUrlString = "https://riot.im/bugreports" static let bugReportSentryEndpoint = "https://f39ac49e97714316965b777d9f3d6cd8@sentry.tools.element.io/44" // Use the name allocated by the bug report server static let bugReportApplicationId = "riot-ios" static let bugReportUISIId = "element-auto-uisi" - static let bugReportGHLabels: [String] = ["Element-X"] + static let bugReportGHLabels = ["Element-X"] // MARK: - Settings screen - static let settingsCrashButtonVisible: Bool = true - static let settingsShowTimelineStyle: Bool = true + + static let settingsCrashButtonVisible = true + static let settingsShowTimelineStyle = true // MARK: - Room screen + static let defaultRoomTimelineStyle: TimelineStyle = .bubbles } diff --git a/ElementX/Sources/Other/Benchmark.swift b/ElementX/Sources/Other/Benchmark.swift index 68a30b897..601965011 100644 --- a/ElementX/Sources/Other/Benchmark.swift +++ b/ElementX/Sources/Other/Benchmark.swift @@ -9,9 +9,9 @@ import Foundation struct Benchmark { - static private var trackingIdentifiers = [String: CFAbsoluteTime]() + private static var trackingIdentifiers = [String: CFAbsoluteTime]() - static public var trackingEnabled = false + public static var trackingEnabled = false static func startTrackingForIdentifier(_ identifier: String, message: String? = nil) { guard trackingEnabled else { diff --git a/ElementX/Sources/Other/BlurHashDecode.swift b/ElementX/Sources/Other/BlurHashDecode.swift index be619b68d..3cf783299 100644 --- a/ElementX/Sources/Other/BlurHashDecode.swift +++ b/ElementX/Sources/Other/BlurHashDecode.swift @@ -2,25 +2,25 @@ import UIKit // swiftlint:disable all -extension UIImage { - public convenience init?(blurHash: String, size: CGSize, punch: Float = 1) { +public extension UIImage { + convenience init?(blurHash: String, size: CGSize, punch: Float = 1) { guard blurHash.count >= 6 else { return nil } - let sizeFlag = String(blurHash[0]).decode83() - let numY = (sizeFlag / 9) + 1 - let numX = (sizeFlag % 9) + 1 + let sizeFlag = String(blurHash[0]).decode83() + let numY = (sizeFlag / 9) + 1 + let numX = (sizeFlag % 9) + 1 - let quantisedMaximumValue = String(blurHash[1]).decode83() + let quantisedMaximumValue = String(blurHash[1]).decode83() let maximumValue = Float(quantisedMaximumValue + 1) / 166 guard blurHash.count == 4 + 2 * numX * numY else { return nil } - let colours: [(Float, Float, Float)] = (0 ..< numX * numY).map { i in + let colours: [(Float, Float, Float)] = (0.. (Float, Float, Float) { } private func decodeAC(_ value: Int, maximumValue: Float) -> (Float, Float, Float) { - let quantR = value / (19 * 19) - let quantG = (value / 19) % 19 - let quantB = value % 19 + let quantR = value / (19 * 19) + let quantG = (value / 19) % 19 + let quantB = value % 19 - let rgb = ( - signPow((Float(quantR) - 9) / 9, 2) * maximumValue, - signPow((Float(quantG) - 9) / 9, 2) * maximumValue, - signPow((Float(quantB) - 9) / 9, 2) * maximumValue - ) + let rgb = ( + signPow((Float(quantR) - 9) / 9, 2) * maximumValue, + signPow((Float(quantG) - 9) / 9, 2) * maximumValue, + signPow((Float(quantB) - 9) / 9, 2) * maximumValue + ) - return rgb + return rgb } private func signPow(_ value: Float, _ exp: Float) -> Float { - return copysign(pow(abs(value), exp), value) + copysign(pow(abs(value), exp), value) } private func linearTosRGB(_ value: Float) -> Int { @@ -105,46 +105,44 @@ private func sRGBToLinear(_ value: Type) -> Float { else { return pow((v + 0.055) / 1.055, 2.4) } } -private let encodeCharacters: [String] = { - return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } -}() +private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } private let decodeCharacters: [String: Int] = { - var dict: [String: Int] = [:] - for (index, character) in encodeCharacters.enumerated() { - dict[character] = index - } - return dict + var dict: [String: Int] = [:] + for (index, character) in encodeCharacters.enumerated() { + dict[character] = index + } + return dict }() extension String { - func decode83() -> Int { - var value: Int = 0 - for character in self { - if let digit = decodeCharacters[String(character)] { - value = value * 83 + digit - } - } - return value - } + func decode83() -> Int { + var value = 0 + for character in self { + if let digit = decodeCharacters[String(character)] { + value = value * 83 + digit + } + } + return value + } } private extension String { - subscript (offset: Int) -> Character { - return self[index(startIndex, offsetBy: offset)] - } + subscript(offset: Int) -> Character { + self[index(startIndex, offsetBy: offset)] + } - subscript (bounds: CountableClosedRange) -> Substring { - let start = index(startIndex, offsetBy: bounds.lowerBound) - let end = index(startIndex, offsetBy: bounds.upperBound) - return self[start...end] - } + subscript(bounds: CountableClosedRange) -> Substring { + let start = index(startIndex, offsetBy: bounds.lowerBound) + let end = index(startIndex, offsetBy: bounds.upperBound) + return self[start...end] + } - subscript (bounds: CountableRange) -> Substring { - let start = index(startIndex, offsetBy: bounds.lowerBound) - let end = index(startIndex, offsetBy: bounds.upperBound) - return self[start..) -> Substring { + let start = index(startIndex, offsetBy: bounds.lowerBound) + let end = index(startIndex, offsetBy: bounds.upperBound) + return self[start.. [String] { var set = Set() return ([Bundle.elementLanguage] + - Locale.preferredLanguages + - [Bundle.elementFallbackLanguage]) - .compactMap { $0 } - .filter { set.insert($0).inserted } + Locale.preferredLanguages + + [Bundle.elementFallbackLanguage]) + .compactMap { $0 } + .filter { set.insert($0).inserted } } } diff --git a/ElementX/Sources/Other/Extensions/String.swift b/ElementX/Sources/Other/Extensions/String.swift index 81f2a1087..17b6b75fe 100644 --- a/ElementX/Sources/Other/Extensions/String.swift +++ b/ElementX/Sources/Other/Extensions/String.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift index 35893e01e..3a21f7f0f 100644 --- a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift +++ b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import DTCoreText +import Foundation struct AttributedStringBuilder: AttributedStringBuilderProtocol { @@ -55,8 +55,8 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { func fromHTML(_ htmlString: String?) -> AttributedString? { guard let htmlString = htmlString, let data = htmlString.data(using: .utf8) else { - return nil - } + return nil + } let defaultFont = UIFont.preferredFont(forTextStyle: .body) @@ -65,7 +65,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { DTDefaultFontFamily: defaultFont.familyName, DTDefaultFontName: defaultFont.fontName, DTDefaultFontSize: defaultFont.pointSize, - DTDefaultStyleSheet: DTCSSStylesheet(styleBlock: self.defaultCSS) as Any + DTDefaultStyleSheet: DTCSSStylesheet(styleBlock: defaultCSS) as Any ] guard let builder = DTHTMLAttributedStringBuilder(html: data, options: parsingOptions, documentAttributes: nil) else { @@ -96,7 +96,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { return nil } - return attributedString.runs[\.blockquote].map { (value, range) in + return attributedString.runs[\.blockquote].map { value, range in var attributedString = AttributedString(attributedString[range]) // Remove trailing new lines if any @@ -119,8 +119,8 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { guard let value = value as? NSArray, let dtTextBlock = value.firstObject as? DTTextBlock, dtTextBlock.backgroundColor == temporaryBlockquoteMarkingColor else { - return - } + return + } attributedString.addAttribute(.MXBlockquote, value: true, range: range) } @@ -128,8 +128,8 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { attributedString.enumerateAttribute(.backgroundColor, in: .init(location: 0, length: attributedString.length), options: []) { value, range, _ in guard let value = value as? UIColor, value == temporaryBlockquoteMarkingColor else { - return - } + return + } attributedString.removeAttribute(.backgroundColor, range: range) attributedString.addAttribute(.MXBlockquote, value: true, range: range) @@ -212,22 +212,22 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { } private var defaultCSS: String { -""" - blockquote { - background: \(temporaryBlockquoteMarkingColor.toHexString()); - display: block; - } - pre,code { - background-color: \(temporaryCodeBlockMarkingColor.toHexString()); - display: inline; - font-family: monospace; - white-space: pre; - -coretext-fontname: Menlo-Regular; - } - h1,h2,h3 { - font-size: 1.2em; - } -""" + """ + blockquote { + background: \(temporaryBlockquoteMarkingColor.toHexString()); + display: block; + } + pre,code { + background-color: \(temporaryCodeBlockMarkingColor.toHexString()); + display: inline; + font-family: monospace; + white-space: pre; + -coretext-fontname: Menlo-Regular; + } + h1,h2,h3 { + font-size: 1.2em; + } + """ } } @@ -240,7 +240,7 @@ extension UIColor { getRed(&red, green: &green, blue: &blue, alpha: &alpha) - let rgb: Int = (Int)(red*255)<<16 | (Int)(green*255)<<8 | (Int)(blue*255)<<0 + let rgb = Int(red * 255) << 16 | Int(green * 255) << 8 | Int(blue * 255) << 0 return NSString(format: "#%06x", rgb) as String } diff --git a/ElementX/Sources/Other/HTMLParsing/DTHTMLElement+AttributedStringBuilder.swift b/ElementX/Sources/Other/HTMLParsing/DTHTMLElement+AttributedStringBuilder.swift index 957691381..e8dfae055 100644 --- a/ElementX/Sources/Other/HTMLParsing/DTHTMLElement+AttributedStringBuilder.swift +++ b/ElementX/Sources/Other/HTMLParsing/DTHTMLElement+AttributedStringBuilder.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import DTCoreText +import Foundation public extension DTHTMLElement { /// Sanitize the element using the given parameters. diff --git a/ElementX/Sources/Other/HTMLParsing/ElementXAttributeScope.swift b/ElementX/Sources/Other/HTMLParsing/ElementXAttributeScope.swift index 3294e3457..9294ffcb3 100644 --- a/ElementX/Sources/Other/HTMLParsing/ElementXAttributeScope.swift +++ b/ElementX/Sources/Other/HTMLParsing/ElementXAttributeScope.swift @@ -26,6 +26,6 @@ extension AttributeScopes { extension AttributeDynamicLookup { subscript(dynamicMember keyPath: KeyPath) -> T { - return self[T.self] + self[T.self] } } diff --git a/ElementX/Sources/Other/ImageAnonymizer.swift b/ElementX/Sources/Other/ImageAnonymizer.swift index 775c31e0b..ac9804d99 100644 --- a/ElementX/Sources/Other/ImageAnonymizer.swift +++ b/ElementX/Sources/Other/ImageAnonymizer.swift @@ -7,14 +7,14 @@ // import Foundation -import Vision import UIKit +import Vision enum ImageAnonymizerError: Error { case noCgImageBased } -struct ImageAnonymizer { +enum ImageAnonymizer { private static var allowedTextItems: [String] = [ "#", @@ -96,7 +96,7 @@ struct ImageAnonymizer { continue } if let textObservation = observation as? VNRecognizedTextObservation, - let text = textObservation.topCandidates(1).first?.string { + let text = textObservation.topCandidates(1).first?.string { if Double(text) != nil || Self.allowedTextItems.contains(text) { continue } diff --git a/ElementX/Sources/Other/Logging/MXLog.swift b/ElementX/Sources/Other/Logging/MXLog.swift index 9f296fde8..03686dea0 100644 --- a/ElementX/Sources/Other/Logging/MXLog.swift +++ b/ElementX/Sources/Other/Logging/MXLog.swift @@ -21,10 +21,10 @@ import SwiftyBeaver @objc public class MXLogConfiguration: NSObject { /// the desired log level. `.verbose` by default. - @objc public var logLevel: MXLogLevel = MXLogLevel.verbose + @objc public var logLevel = MXLogLevel.verbose /// whether logs should be written directly to files. `false` by default. - @objc public var redirectLogsToFiles: Bool = false + @objc public var redirectLogsToFiles = false /// the maximum total space to use for log files in bytes. `100MB` by default. @objc public var logFilesSizeLimit: UInt = 100 * 1024 * 1024 // 100MB @@ -64,7 +64,7 @@ private var logger: SwiftyBeaver.Type = { /// Please see `MXLogConfiguration` for all available options. /// - Parameters: /// - configuration: the `MXLogConfiguration` instance to use - @objc static public func configure(_ configuration: MXLogConfiguration) { + @objc public static func configure(_ configuration: MXLogConfiguration) { configureLogger(logger, withConfiguration: configuration) } @@ -107,8 +107,8 @@ private var logger: SwiftyBeaver.Type = { logger.info(message, file, function, line: line) } - public static func warning(_ message: @autoclosure () -> Any, _ - file: String = #file, + public static func warning(_ message: @autoclosure () -> Any, + _ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) { @@ -133,8 +133,8 @@ private var logger: SwiftyBeaver.Type = { logger.error(message, file, function, line: line) } - public static func failure(_ message: @autoclosure () -> Any, _ - file: String = #file, + public static func failure(_ message: @autoclosure () -> Any, + _ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) { diff --git a/ElementX/Sources/Other/Routers/NavigationModule.swift b/ElementX/Sources/Other/Routers/NavigationModule.swift index 9ad20d3cb..ce2f3789c 100644 --- a/ElementX/Sources/Other/Routers/NavigationModule.swift +++ b/ElementX/Sources/Other/Routers/NavigationModule.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ struct NavigationModule { extension NavigationModule: CustomStringConvertible { var description: String { - return "NavigationModule: \(presentable), pop completion: \(String(describing: popCompletion))" + "NavigationModule: \(presentable), pop completion: \(String(describing: popCompletion))" } } diff --git a/ElementX/Sources/Other/Routers/NavigationRouter.swift b/ElementX/Sources/Other/Routers/NavigationRouter.swift index 44f443d2c..b68c19183 100755 --- a/ElementX/Sources/Other/Routers/NavigationRouter.swift +++ b/ElementX/Sources/Other/Routers/NavigationRouter.swift @@ -23,7 +23,7 @@ final class NavigationRouter: NSObject, NavigationRouterType { // MARK: Private - private var completions: [UIViewController : () -> Void] + private var completions: [UIViewController: () -> Void] private let navigationController: UINavigationController /// Stores the association between the added Presentable and his view controller. @@ -34,34 +34,34 @@ final class NavigationRouter: NSObject, NavigationRouterType { /// Returns the presentables associated to each view controller var modules: [Presentable] { - return self.viewControllers.map { (viewController) -> Presentable in - return self.module(for: viewController) + viewControllers.map { viewController -> Presentable in + self.module(for: viewController) } } /// Return the view controllers stack var viewControllers: [UIViewController] { - return navigationController.viewControllers + navigationController.viewControllers } // MARK: - Setup init(navigationController: UINavigationController) { self.navigationController = navigationController - self.completions = [:] + completions = [:] super.init() self.navigationController.delegate = self // Post local notification on NavigationRouter creation let userInfo: [String: Any] = [NavigationRouter.NotificationUserInfoKey.navigationRouter: self, - NavigationRouter.NotificationUserInfoKey.navigationController: navigationController] + NavigationRouter.NotificationUserInfoKey.navigationController: navigationController] NotificationCenter.default.post(name: NavigationRouter.didCreate, object: self, userInfo: userInfo) } deinit { // Post local notification on NavigationRouter deinit let userInfo: [String: Any] = [NavigationRouter.NotificationUserInfoKey.navigationRouter: self, - NavigationRouter.NotificationUserInfoKey.navigationController: navigationController] + NavigationRouter.NotificationUserInfoKey.navigationController: navigationController] NotificationCenter.default.post(name: NavigationRouter.willDestroy, object: self, userInfo: userInfo) } @@ -88,9 +88,9 @@ final class NavigationRouter: NSObject, NavigationRouterType { return } - self.addModule(module, for: controller) + addModule(module, for: controller) - let controllersToPop = self.navigationController.viewControllers.reversed() + let controllersToPop = navigationController.viewControllers.reversed() controllersToPop.forEach { self.willPopViewController($0) @@ -100,7 +100,7 @@ final class NavigationRouter: NSObject, NavigationRouterType { completions[controller] = popCompletion } - self.willPushViewController(controller) + willPushViewController(controller) navigationController.setViewControllers([controller], animated: animated) navigationController.isNavigationBarHidden = hideNavigationBar @@ -111,22 +111,22 @@ final class NavigationRouter: NSObject, NavigationRouterType { } // Add again controller to module association, in case same module instance is added back - self.addModule(module, for: controller) + addModule(module, for: controller) - self.didPushViewController(controller) + didPushViewController(controller) } func setModules(_ modules: [NavigationModule], hideNavigationBar: Bool, animated: Bool) { MXLog.debug("[NavigationRouter] Set modules \(modules)") - let controllers = modules.map { (module) -> UIViewController in + let controllers = modules.map { module -> UIViewController in let controller = module.presentable.toPresentable() self.addModule(module.presentable, for: controller) return controller } - let controllersToPop = self.navigationController.viewControllers.reversed() + let controllersToPop = navigationController.viewControllers.reversed() controllersToPop.forEach { self.willPopViewController($0) @@ -146,7 +146,7 @@ final class NavigationRouter: NSObject, NavigationRouterType { } // Add again controller to module association, in case same modules instance are added back - modules.forEach { (module) in + modules.forEach { module in self.addModule(module.presentable, for: module.presentable.toPresentable()) } @@ -158,7 +158,7 @@ final class NavigationRouter: NSObject, NavigationRouterType { func popToRootModule(animated: Bool) { MXLog.debug("[NavigationRouter] Pop to root module") - let controllers = self.navigationController.viewControllers + let controllers = navigationController.viewControllers if controllers.count > 1 { let controllersToPop = controllers[1.. Bool { let controller = module.toPresentable() - return self.navigationController.viewControllers.contains(controller) + return navigationController.viewControllers.contains(controller) } // MARK: Presentable func toPresentable() -> UIViewController { - return navigationController + navigationController } // MARK: - Private private func module(for viewController: UIViewController) -> Presentable { - guard let module = self.storedModules[viewController] as? Presentable else { + guard let module = storedModules[viewController] as? Presentable else { return viewController } return module } private func addModule(_ module: Presentable, for viewController: UIViewController) { - self.storedModules[viewController] = module as AnyObject + storedModules[viewController] = module as AnyObject } private func removeModule(for viewController: UIViewController) { - self.storedModules[viewController] = nil + storedModules[viewController] = nil } private func runCompletion(for controller: UIViewController) { @@ -317,30 +317,30 @@ final class NavigationRouter: NSObject, NavigationRouterType { } private func willPushViewController(_ viewController: UIViewController) { - self.postNotification(withName: NavigationRouter.willPushModule, for: viewController) + postNotification(withName: NavigationRouter.willPushModule, for: viewController) } private func didPushViewController(_ viewController: UIViewController) { - self.postNotification(withName: NavigationRouter.didPushModule, for: viewController) + postNotification(withName: NavigationRouter.didPushModule, for: viewController) } private func willPopViewController(_ viewController: UIViewController) { - self.postNotification(withName: NavigationRouter.willPopModule, for: viewController) + postNotification(withName: NavigationRouter.willPopModule, for: viewController) } - private func didPopViewController(_ viewController: UIViewController) { - self.postNotification(withName: NavigationRouter.didPopModule, for: viewController) + private func didPopViewController(_ viewController: UIViewController) { + postNotification(withName: NavigationRouter.didPopModule, for: viewController) // Call completion closure associated to the view controller // So associated coordinator can be deallocated runCompletion(for: viewController) - self.removeModule(for: viewController) + removeModule(for: viewController) } private func postNotification(withName name: Notification.Name, for viewController: UIViewController) { - let module = self.module(for: viewController) + let module = module(for: viewController) let userInfo: [String: Any] = [ NotificationUserInfoKey.navigationRouter: self, @@ -352,6 +352,7 @@ final class NavigationRouter: NSObject, NavigationRouterType { } // MARK: - UINavigationControllerDelegate + extension NavigationRouter: UINavigationControllerDelegate { func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { @@ -363,17 +364,18 @@ extension NavigationRouter: UINavigationControllerDelegate { // Ensure the view controller is popping guard let poppedViewController = navigationController.transitionCoordinator?.viewController(forKey: .from), - !navigationController.viewControllers.contains(poppedViewController) else { - return + !navigationController.viewControllers.contains(poppedViewController) else { + return } MXLog.debug("[NavigationRouter] Popped module: \(poppedViewController)") - self.didPopViewController(poppedViewController) + didPopViewController(poppedViewController) } } // MARK: - NavigationRouter notification constants + extension NavigationRouter { // MARK: Notification names @@ -388,7 +390,7 @@ extension NavigationRouter { // MARK: Notification keys - public struct NotificationUserInfoKey { + public enum NotificationUserInfoKey { /// The associated view controller (UIViewController). static let viewController = "viewController" diff --git a/ElementX/Sources/Other/Routers/NavigationRouterStore.swift b/ElementX/Sources/Other/Routers/NavigationRouterStore.swift index 8b25814c7..e130f18cd 100644 --- a/ElementX/Sources/Other/Routers/NavigationRouterStore.swift +++ b/ElementX/Sources/Other/Routers/NavigationRouterStore.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,7 +25,7 @@ class NavigationRouterStore: NavigationRouterStoreProtocol { // MARK: - Properties - // WeakDictionary does not work with protocol + // WeakDictionary does not work with protocol // Find a way to use NavigationRouterType as value private var navigationRouters = WeakDictionary() @@ -33,14 +33,14 @@ class NavigationRouterStore: NavigationRouterStoreProtocol { /// As we are ensuring that there is only one navigation controller per NavigationRouter, the class here should be used as a singleton. private init() { - self.registerNavigationRouterNotifications() + registerNavigationRouterNotifications() } // MARK: - Public func navigationRouter(for navigationController: UINavigationController) -> NavigationRouterType { - if let existingNavigationRouter = self.findNavigationRouter(for: navigationController) { + if let existingNavigationRouter = findNavigationRouter(for: navigationController) { return existingNavigationRouter } @@ -51,11 +51,11 @@ class NavigationRouterStore: NavigationRouterStoreProtocol { // MARK: - Private private func findNavigationRouter(for navigationController: UINavigationController) -> NavigationRouterType? { - return self.navigationRouters[navigationController] + navigationRouters[navigationController] } private func removeNavigationRouter(for navigationController: UINavigationController) { - self.navigationRouters[navigationController] = nil + navigationRouters[navigationController] = nil } private func registerNavigationRouterNotifications() { @@ -71,12 +71,12 @@ class NavigationRouterStore: NavigationRouterStoreProtocol { return } - if let existingNavigationRouter = self.findNavigationRouter(for: navigationController) { + if let existingNavigationRouter = findNavigationRouter(for: navigationController) { fatalError("\(existingNavigationRouter) is already tied to the same navigation controller as \(navigationRouter). We should have only one NavigationRouter per navigation controller") } else { // WeakDictionary does not work with protocol // Find a way to avoid this cast - self.navigationRouters[navigationController] = navigationRouter as? NavigationRouter + navigationRouters[navigationController] = navigationRouter as? NavigationRouter } } @@ -87,10 +87,10 @@ class NavigationRouterStore: NavigationRouterStoreProtocol { return } - if let existingNavigationRouter = self.findNavigationRouter(for: navigationController), existingNavigationRouter !== navigationRouter { + if let existingNavigationRouter = findNavigationRouter(for: navigationController), existingNavigationRouter !== navigationRouter { fatalError("\(existingNavigationRouter) is already tied to the same navigation controller as \(navigationRouter). We should have only one NavigationRouter per navigation controller") } - self.removeNavigationRouter(for: navigationController) + removeNavigationRouter(for: navigationController) } } diff --git a/ElementX/Sources/Other/Routers/NavigationRouterStoreProtocol.swift b/ElementX/Sources/Other/Routers/NavigationRouterStoreProtocol.swift index ad5fb663f..be48666ad 100644 --- a/ElementX/Sources/Other/Routers/NavigationRouterStoreProtocol.swift +++ b/ElementX/Sources/Other/Routers/NavigationRouterStoreProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/Routers/Presentable.swift b/ElementX/Sources/Other/Routers/Presentable.swift index 2d6e4048e..dcb9c4154 100755 --- a/ElementX/Sources/Other/Routers/Presentable.swift +++ b/ElementX/Sources/Other/Routers/Presentable.swift @@ -24,7 +24,7 @@ protocol Presentable { extension UIViewController: Presentable { public func toPresentable() -> UIViewController { - return self + self } } @@ -33,7 +33,7 @@ extension Presentable { /// Returns a new module from the presentable without a pop completion block /// - Returns: Module func toModule() -> NavigationModule { - return NavigationModule(presentable: self, popCompletion: nil) + NavigationModule(presentable: self, popCompletion: nil) } } diff --git a/ElementX/Sources/Other/Routers/RootRouter.swift b/ElementX/Sources/Other/Routers/RootRouter.swift index dd9f76e91..bea2ed741 100755 --- a/ElementX/Sources/Other/Routers/RootRouter.swift +++ b/ElementX/Sources/Other/Routers/RootRouter.swift @@ -33,9 +33,9 @@ final class RootRouter: RootRouterType { let window: UIWindow - /// The root view controller currently presented + /// The root view controller currently presented var rootViewController: UIViewController? { - return self.window.rootViewController + window.rootViewController } // MARK: - Setup @@ -47,23 +47,23 @@ final class RootRouter: RootRouterType { // MARK: - Public methods func setRootModule(_ module: Presentable) { - self.updateRootViewController(rootViewController: module.toPresentable(), animated: false, completion: nil) - self.window.makeKeyAndVisible() + updateRootViewController(rootViewController: module.toPresentable(), animated: false, completion: nil) + window.makeKeyAndVisible() } func dismissRootModule(animated: Bool, completion: (() -> Void)?) { - self.updateRootViewController(rootViewController: nil, animated: animated, completion: completion) + updateRootViewController(rootViewController: nil, animated: animated, completion: completion) } func presentModule(_ module: Presentable, animated: Bool, completion: (() -> Void)?) { - let viewControllerPresenter = self.rootViewController?.presentedViewController ?? self.rootViewController + let viewControllerPresenter = rootViewController?.presentedViewController ?? rootViewController viewControllerPresenter?.present(module.toPresentable(), animated: animated, completion: completion) - self.presentedModule = module + presentedModule = module } func dismissModule(animated: Bool, completion: (() -> Void)?) { - self.presentedModule?.toPresentable().dismiss(animated: animated, completion: completion) + presentedModule?.toPresentable().dismiss(animated: animated, completion: completion) } // MARK: - Private methods @@ -76,11 +76,11 @@ final class RootRouter: RootRouterType { UIView.setAnimationsEnabled(false) self.window.rootViewController = rootViewController UIView.setAnimationsEnabled(oldState) - }, completion: { (_: Bool) -> Void in + }, completion: { _ in completion?() }) } else { - self.window.rootViewController = rootViewController + window.rootViewController = rootViewController completion?() } } diff --git a/ElementX/Sources/Other/Routers/RootRouterType.swift b/ElementX/Sources/Other/Routers/RootRouterType.swift index 4d956acee..6fd49d1b2 100755 --- a/ElementX/Sources/Other/Routers/RootRouterType.swift +++ b/ElementX/Sources/Other/Routers/RootRouterType.swift @@ -19,12 +19,12 @@ import UIKit /// Protocol describing a router that wraps the root navigation of the application. /// Routers are used to be passed between coordinators. They handles only `physical` navigation. @MainActor -protocol RootRouterType: AnyObject { +protocol RootRouterType: AnyObject { /// Update the root view controller /// /// - Parameter module: The new root view controller to set - func setRootModule(_ module: Presentable) + func setRootModule(_ module: Presentable) /// Dismiss the root view controller /// diff --git a/ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift b/ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift index 58213cd72..3c8d224b1 100644 --- a/ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift +++ b/ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/SwiftUI/Layout/FramePreferenceKey.swift b/ElementX/Sources/Other/SwiftUI/Layout/FramePreferenceKey.swift index 1eb7e97dd..63eb8df9d 100644 --- a/ElementX/Sources/Other/SwiftUI/Layout/FramePreferenceKey.swift +++ b/ElementX/Sources/Other/SwiftUI/Layout/FramePreferenceKey.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.swift b/ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.swift index eb44a9496..257431e35 100644 --- a/ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.swift +++ b/ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,9 @@ import SwiftUI -// swiftlint:disable private_over_fileprivate - /// Positions this view within an invisible frame that fills the width of its parent view, /// whilst limiting the width of the content to a readable size (which is customizable). -fileprivate struct ReadableFrameModifier: ViewModifier { +private struct ReadableFrameModifier: ViewModifier { var maxWidth: CGFloat func body(content: Content) -> some View { diff --git a/ElementX/Sources/Other/SwiftUI/Layout/ViewFrameReader.swift b/ElementX/Sources/Other/SwiftUI/Layout/ViewFrameReader.swift index 834c018a7..1bb6c50de 100644 --- a/ElementX/Sources/Other/SwiftUI/Layout/ViewFrameReader.swift +++ b/ElementX/Sources/Other/SwiftUI/Layout/ViewFrameReader.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/SwiftUI/ViewModel/BindableState.swift b/ElementX/Sources/Other/SwiftUI/ViewModel/BindableState.swift index b5d2785d6..eaaf48e30 100644 --- a/ElementX/Sources/Other/SwiftUI/ViewModel/BindableState.swift +++ b/ElementX/Sources/Other/SwiftUI/ViewModel/BindableState.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,9 +27,7 @@ extension BindableState where BindStateType == Void { /// We provide a default implementation for the Void type so that we can have `ViewState` that /// just doesn't include/take advantage of the bindings. var bindings: Void { - get { - - } + get { } set { fatalError("Can't bind to the default Void binding.") } diff --git a/ElementX/Sources/Other/SwiftUI/ViewModel/StateStoreViewModel.swift b/ElementX/Sources/Other/SwiftUI/ViewModel/StateStoreViewModel.swift index 0b38a4404..d85440cbb 100644 --- a/ElementX/Sources/Other/SwiftUI/ViewModel/StateStoreViewModel.swift +++ b/ElementX/Sources/Other/SwiftUI/ViewModel/StateStoreViewModel.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import Foundation import Combine +import Foundation /// A constrained and concise interface for interacting with the ViewModel. /// @@ -96,8 +96,8 @@ class StateStoreViewModel { // MARK: Setup init(initialViewState: State) { - self.context = Context(initialViewState: initialViewState) - self.context.viewActions.sink { [weak self] action in + context = Context(initialViewState: initialViewState) + context.viewActions.sink { [weak self] action in guard let self = self else { return } Task { await self.process(viewAction: action) } diff --git a/ElementX/Sources/Other/UserIndicators/ActivityIndicatorPresenter.swift b/ElementX/Sources/Other/UserIndicators/ActivityIndicatorPresenter.swift index 25c2787f5..47e5e887f 100755 --- a/ElementX/Sources/Other/UserIndicators/ActivityIndicatorPresenter.swift +++ b/ElementX/Sources/Other/UserIndicators/ActivityIndicatorPresenter.swift @@ -52,7 +52,7 @@ final class ActivityIndicatorPresenter: ActivityIndicatorPresenterType { view.isUserInteractionEnabled = false - let backgroundOverlayView = self.createBackgroundOverlayView(with: view.frame) + let backgroundOverlayView = createBackgroundOverlayView(with: view.frame) let activityIndicatorView = ActivityIndicatorView() @@ -89,9 +89,9 @@ final class ActivityIndicatorPresenter: ActivityIndicatorPresenterType { } func removeCurrentActivityIndicator(animated: Bool, completion: (() -> Void)? = nil) { - guard let presentingView = self.presentingView, - let backgroundOverlayView = self.backgroundOverlayView, - let activityIndicatorView = self.activityIndicatorView else { + guard let presentingView = presentingView, + let backgroundOverlayView = backgroundOverlayView, + let activityIndicatorView = activityIndicatorView else { return } diff --git a/ElementX/Sources/Other/UserIndicators/ActivityIndicatorView.swift b/ElementX/Sources/Other/UserIndicators/ActivityIndicatorView.swift index 95fb55d96..43e85660b 100755 --- a/ElementX/Sources/Other/UserIndicators/ActivityIndicatorView.swift +++ b/ElementX/Sources/Other/UserIndicators/ActivityIndicatorView.swift @@ -29,23 +29,23 @@ final class ActivityIndicatorView: UIView { // MARK: Outlets - @IBOutlet private weak var activityIndicatorView: UIActivityIndicatorView! - @IBOutlet private weak var activityIndicatorBackgroundView: UIView! + @IBOutlet private var activityIndicatorView: UIActivityIndicatorView! + @IBOutlet private var activityIndicatorBackgroundView: UIView! // MARK: Public var color: UIColor? { get { - return activityIndicatorView.color + activityIndicatorView.color } - set { + set { activityIndicatorView.color = newValue } } // MARK: - Setup - private func commonInit() { + private func commonInit() { activityIndicatorBackgroundView.layer.masksToBounds = true } @@ -68,8 +68,8 @@ final class ActivityIndicatorView: UIView { // MARK: - Overrides override var intrinsicContentSize: CGSize { - return CGSize(width: activityIndicatorView.intrinsicContentSize.width + Constants.activityIndicatorMargin.width, - height: activityIndicatorView.intrinsicContentSize.height + Constants.activityIndicatorMargin.height) + CGSize(width: activityIndicatorView.intrinsicContentSize.width + Constants.activityIndicatorMargin.width, + height: activityIndicatorView.intrinsicContentSize.height + Constants.activityIndicatorMargin.height) } override func layoutSubviews() { @@ -91,22 +91,22 @@ final class ActivityIndicatorView: UIView { private extension UIView { static var nib: UINib { - return UINib(nibName: String(describing: self), bundle: Bundle(for: self)) + UINib(nibName: String(describing: self), bundle: Bundle(for: self)) } func loadNibContent() { - let layoutAttributes: [NSLayoutConstraint.Attribute] = [.top, .leading, .bottom, .trailing] - for case let view as UIView in type(of: self).nib.instantiate(withOwner: self, options: nil) { - view.translatesAutoresizingMaskIntoConstraints = false - addSubview(view) - NSLayoutConstraint.activate(layoutAttributes.map { attribute in - NSLayoutConstraint( - item: view, attribute: attribute, - relatedBy: .equal, - toItem: self, attribute: attribute, - multiplier: 1, constant: 0.0 - ) - }) - } + let layoutAttributes: [NSLayoutConstraint.Attribute] = [.top, .leading, .bottom, .trailing] + for case let view as UIView in type(of: self).nib.instantiate(withOwner: self, options: nil) { + view.translatesAutoresizingMaskIntoConstraints = false + addSubview(view) + NSLayoutConstraint.activate(layoutAttributes.map { attribute in + NSLayoutConstraint( + item: view, attribute: attribute, + relatedBy: .equal, + toItem: self, attribute: attribute, + multiplier: 1, constant: 0.0 + ) + }) + } } } diff --git a/ElementX/Sources/Other/UserIndicators/FullscreenLoadingViewPresenter.swift b/ElementX/Sources/Other/UserIndicators/FullscreenLoadingViewPresenter.swift index ca4404680..a945a73ec 100644 --- a/ElementX/Sources/Other/UserIndicators/FullscreenLoadingViewPresenter.swift +++ b/ElementX/Sources/Other/UserIndicators/FullscreenLoadingViewPresenter.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/LabelledActivityIndicatorView.swift b/ElementX/Sources/Other/UserIndicators/LabelledActivityIndicatorView.swift index 848e5328f..ac3f79cf9 100644 --- a/ElementX/Sources/Other/UserIndicators/LabelledActivityIndicatorView.swift +++ b/ElementX/Sources/Other/UserIndicators/LabelledActivityIndicatorView.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -49,15 +49,14 @@ final class LabelledActivityIndicatorView: UIView { return view }() - private let label: UILabel = { - UILabel() - }() + private let label = UILabel() init(text: String) { super.init(frame: .zero) setup(text: text) } + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/ElementX/Sources/Other/UserIndicators/RectangleToastView.swift b/ElementX/Sources/Other/UserIndicators/RectangleToastView.swift index b624b44ce..b59aa1935 100644 --- a/ElementX/Sources/Other/UserIndicators/RectangleToastView.swift +++ b/ElementX/Sources/Other/UserIndicators/RectangleToastView.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ import UIKit class RectangleToastView: UIView { private enum Constants { - static let padding: UIEdgeInsets = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) + static let padding = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) static let cornerRadius: CGFloat = 8.0 } @@ -81,6 +81,7 @@ class RectangleToastView: UIView { layer.masksToBounds = true } + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/ElementX/Sources/Other/UserIndicators/RoundedToastView.swift b/ElementX/Sources/Other/UserIndicators/RoundedToastView.swift index 53d892a3b..eaaa764fa 100644 --- a/ElementX/Sources/Other/UserIndicators/RoundedToastView.swift +++ b/ElementX/Sources/Other/UserIndicators/RoundedToastView.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ class RoundedToastView: UIView { let opacity: Float } - private struct Constants { + private enum Constants { static let padding = UIEdgeInsets(top: 10, left: 12, bottom: 10, right: 12) static let activityIndicatorScale = CGFloat(0.75) static let imageViewSize = CGFloat(15) @@ -57,15 +57,14 @@ class RoundedToastView: UIView { return stack }() - private let label: UILabel = { - UILabel() - }() + private let label = UILabel() init(viewState: ToastViewState) { super.init(frame: .zero) setup(viewState: viewState) } + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/ElementX/Sources/Other/UserIndicators/ToastViewPresenter.swift b/ElementX/Sources/Other/UserIndicators/ToastViewPresenter.swift index 5785ed6ac..191920c6a 100644 --- a/ElementX/Sources/Other/UserIndicators/ToastViewPresenter.swift +++ b/ElementX/Sources/Other/UserIndicators/ToastViewPresenter.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ import UIKit /// A presenter responsible for showing / hiding a toast view for loading spinners or success messages. /// It is managed by an `UserIndicator`, meaning the `present` and `dismiss` methods will be called when the parent `UserIndicator` starts or completes. class ToastViewPresenter: UserIndicatorViewPresentable { - struct Constants { + enum Constants { static let navigationBarPatting = CGFloat(10) } diff --git a/ElementX/Sources/Other/UserIndicators/ToastViewState.swift b/ElementX/Sources/Other/UserIndicators/ToastViewState.swift index 341dce195..e183e2947 100644 --- a/ElementX/Sources/Other/UserIndicators/ToastViewState.swift +++ b/ElementX/Sources/Other/UserIndicators/ToastViewState.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicator.swift b/ElementX/Sources/Other/UserIndicators/UserIndicator.swift index d2ad5ab2d..6d2b37df4 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicator.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicator.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorDismissal.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorDismissal.swift index 874a4f1ed..e7b32fb53 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorDismissal.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorDismissal.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorPresentationContext.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorPresentationContext.swift index 30e09f1e0..4f3477b7d 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorPresentationContext.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorPresentationContext.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorPresenter.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorPresenter.swift index 848a00595..ce5eb821b 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorPresenter.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorPresenter.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorQueue.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorQueue.swift index a2ba49fcf..1b798b36d 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorQueue.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorQueue.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorRequest.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorRequest.swift index 97611eeea..c662a53d0 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorRequest.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorRequest.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorStore.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorStore.swift index 20fd8b7a7..7a44a6b02 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorStore.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorStore.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/UserIndicators/UserIndicatorViewPresentable.swift b/ElementX/Sources/Other/UserIndicators/UserIndicatorViewPresentable.swift index 32833da6e..1d633279b 100644 --- a/ElementX/Sources/Other/UserIndicators/UserIndicatorViewPresentable.swift +++ b/ElementX/Sources/Other/UserIndicators/UserIndicatorViewPresentable.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Other/WeakDictionary/WeakDictionary.swift b/ElementX/Sources/Other/WeakDictionary/WeakDictionary.swift index d6cd8efbd..11ae71c25 100644 --- a/ElementX/Sources/Other/WeakDictionary/WeakDictionary.swift +++ b/ElementX/Sources/Other/WeakDictionary/WeakDictionary.swift @@ -18,7 +18,7 @@ public struct WeakDictionary { public init(dictionary: [Key: Value]) { var newStorage = [Key: WeakDictionaryReference]() - dictionary.forEach({ key, value in newStorage[key] = WeakDictionaryReference(value: value) }) + dictionary.forEach { key, value in newStorage[key] = WeakDictionaryReference(value: value) } self.init(storage: newStorage) } @@ -31,7 +31,7 @@ public struct WeakDictionary { } public func weakDictionary() -> WeakDictionary { - return self[startIndex ..< endIndex] + self[startIndex.. [Key: Value] { @@ -52,15 +52,15 @@ extension WeakDictionary: Collection { public typealias Index = DictionaryIndex> public var startIndex: Index { - return storage.startIndex + storage.startIndex } public var endIndex: Index { - return storage.endIndex + storage.endIndex } public func index(after index: Index) -> Index { - return storage.index(after: index) + storage.index(after: index) } public subscript(position: Index) -> (Key, WeakDictionaryReference) { @@ -87,18 +87,18 @@ extension WeakDictionary: Collection { } public subscript(bounds: Range) -> WeakDictionary { - let subStorage = storage[bounds.lowerBound ..< bounds.upperBound] + let subStorage = storage[bounds.lowerBound..]() - subStorage.filter { _, value in return value.value != nil } + subStorage.filter { _, value in value.value != nil } .forEach { key, value in newStorage[key] = value } return WeakDictionary(storage: newStorage) } } -extension Dictionary where Value: AnyObject { - public func weakDictionary() -> WeakDictionary { - return WeakDictionary(dictionary: self) +public extension Dictionary where Value: AnyObject { + func weakDictionary() -> WeakDictionary { + WeakDictionary(dictionary: self) } } diff --git a/ElementX/Sources/Other/WeakDictionary/WeakDictionaryKeyReference.swift b/ElementX/Sources/Other/WeakDictionary/WeakDictionaryKeyReference.swift index 3fcfa539b..1aa6e01b9 100644 --- a/ElementX/Sources/Other/WeakDictionary/WeakDictionaryKeyReference.swift +++ b/ElementX/Sources/Other/WeakDictionary/WeakDictionaryKeyReference.swift @@ -8,7 +8,7 @@ import Foundation -public struct WeakDictionaryKey : Hashable { +public struct WeakDictionaryKey: Hashable { private weak var baseKey: Key? private let hash: Int @@ -22,7 +22,7 @@ public struct WeakDictionaryKey : H } public static func == (lhs: WeakDictionaryKey, rhs: WeakDictionaryKey) -> Bool { - return (lhs.baseKey != nil && rhs.baseKey != nil && lhs.baseKey == rhs.baseKey) + (lhs.baseKey != nil && rhs.baseKey != nil && lhs.baseKey == rhs.baseKey) || lhs.hashValue == rhs.hashValue } @@ -35,6 +35,6 @@ public struct WeakDictionaryKey : H } public var key: Key? { - return baseKey + baseKey } } diff --git a/ElementX/Sources/Other/WeakDictionary/WeakDictionaryReference.swift b/ElementX/Sources/Other/WeakDictionary/WeakDictionaryReference.swift index c1789da4f..ad2e48e9f 100644 --- a/ElementX/Sources/Other/WeakDictionary/WeakDictionaryReference.swift +++ b/ElementX/Sources/Other/WeakDictionary/WeakDictionaryReference.swift @@ -16,6 +16,6 @@ public struct WeakDictionaryReference { } public var value: Value? { - return referencedValue + referencedValue } } diff --git a/ElementX/Sources/Other/WeakDictionary/WeakKeyDictionary.swift b/ElementX/Sources/Other/WeakDictionary/WeakKeyDictionary.swift index 7d804c161..cc9f606b5 100644 --- a/ElementX/Sources/Other/WeakDictionary/WeakKeyDictionary.swift +++ b/ElementX/Sources/Other/WeakDictionary/WeakKeyDictionary.swift @@ -48,11 +48,11 @@ public struct WeakKeyDictionary { } public func weakDictionary() -> WeakDictionary { - return dictionary().weakDictionary() + dictionary().weakDictionary() } public func weakKeyDictionary() -> WeakKeyDictionary { - return self[startIndex ..< endIndex] + self[startIndex.. [Key: Value] { @@ -73,15 +73,15 @@ extension WeakKeyDictionary: Collection { public typealias Index = DictionaryIndex, WeakDictionaryReference> public var startIndex: Index { - return storage.startIndex + storage.startIndex } public var endIndex: Index { - return storage.endIndex + storage.endIndex } public func index(after index: Index) -> Index { - return storage.index(after: index) + storage.index(after: index) } public subscript(position: Index) -> (WeakDictionaryKey, WeakDictionaryReference) { @@ -90,7 +90,7 @@ extension WeakKeyDictionary: Collection { public subscript(key: Key) -> Value? { get { - return storage[WeakDictionaryKey(key: key)] + storage[WeakDictionaryKey(key: key)] } set { @@ -101,24 +101,24 @@ extension WeakKeyDictionary: Collection { } public subscript(bounds: Range) -> WeakKeyDictionary { - let subStorage = storage[bounds.lowerBound ..< bounds.upperBound] + let subStorage = storage[bounds.lowerBound.., Value>() - subStorage.filter { key, value in return key.key != nil && value.value != nil } + subStorage.filter { key, value in key.key != nil && value.value != nil } .forEach { key, value in newStorage[key] = value.value } return WeakKeyDictionary(storage: newStorage) } } -extension WeakDictionary where Key: AnyObject { - public func weakKeyDictionary(valuesRetainedByKey: Bool = false) -> WeakKeyDictionary { - return WeakKeyDictionary(dictionary: dictionary(), valuesRetainedByKey: valuesRetainedByKey) +public extension WeakDictionary where Key: AnyObject { + func weakKeyDictionary(valuesRetainedByKey: Bool = false) -> WeakKeyDictionary { + WeakKeyDictionary(dictionary: dictionary(), valuesRetainedByKey: valuesRetainedByKey) } } -extension Dictionary where Key: AnyObject, Value: AnyObject { - public func weakKeyDictionary(valuesRetainedByKey: Bool = false) -> WeakKeyDictionary { - return WeakKeyDictionary(dictionary: self, valuesRetainedByKey: valuesRetainedByKey) +public extension Dictionary where Key: AnyObject, Value: AnyObject { + func weakKeyDictionary(valuesRetainedByKey: Bool = false) -> WeakKeyDictionary { + WeakKeyDictionary(dictionary: self, valuesRetainedByKey: valuesRetainedByKey) } } diff --git a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift index 28481c12c..b1111c36e 100644 --- a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import MatrixRustSDK +import UIKit @MainActor protocol AuthenticationCoordinatorDelegate: AnyObject { diff --git a/ElementX/Sources/Screens/Authentication/AuthenticationIconImage.swift b/ElementX/Sources/Screens/Authentication/AuthenticationIconImage.swift index a45247157..58939f9dd 100644 --- a/ElementX/Sources/Screens/Authentication/AuthenticationIconImage.swift +++ b/ElementX/Sources/Screens/Authentication/AuthenticationIconImage.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift index 4f2a63601..a8918de00 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import MatrixRustSDK +import SwiftUI struct LoginCoordinatorParameters { /// The service used to authenticate the user. @@ -56,7 +56,7 @@ final class LoginCoordinator: Coordinator, Presentable { // Must be used only internally var childCoordinators: [Coordinator] = [] - var callback: (@MainActor (LoginCoordinatorAction) -> Void)? + var callback: (@MainActor(LoginCoordinatorAction) -> Void)? // MARK: - Setup @@ -73,6 +73,7 @@ final class LoginCoordinator: Coordinator, Presentable { } // MARK: - Public + func start() { MXLog.debug("[LoginCoordinator] did start.") diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginHomeserver.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginHomeserver.swift index cdc838918..bb43df847 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginHomeserver.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginHomeserver.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginMode.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginMode.swift index abee84de6..ce7109f26 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginMode.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginMode.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginModels.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginModels.swift index 294a9d760..5a5c6e4df 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginModels.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginModels.swift @@ -53,7 +53,7 @@ struct LoginViewState: BindableState { /// Data about the selected homeserver. var homeserver: LoginHomeserver /// Whether a new homeserver is currently being loaded. - var isLoading: Bool = false + var isLoading = false /// View state that can be bound to from SwiftUI. var bindings: LoginBindings diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModel.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModel.swift index 97f65298a..57255691f 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModel.swift @@ -24,7 +24,7 @@ class LoginViewModel: LoginViewModelType, LoginViewModelProtocol { // MARK: Public - var callback: (@MainActor (LoginViewModelAction) -> Void)? + var callback: (@MainActor(LoginViewModelAction) -> Void)? // MARK: - Setup diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModelProtocol.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModelProtocol.swift index ad2766a92..1b5d9eab0 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModelProtocol.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ import Foundation @MainActor protocol LoginViewModelProtocol { - var callback: (@MainActor (LoginViewModelAction) -> Void)? { get set } + var callback: (@MainActor(LoginViewModelAction) -> Void)? { get set } var context: LoginViewModelType.Context { get } /// Update the view to reflect that a new homeserver is being loaded. diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginServerInfoSection.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginServerInfoSection.swift index 4fa5ca156..35b9d7fce 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginServerInfoSection.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginServerInfoSection.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift index f891a4021..82dbfe325 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift @@ -46,7 +46,7 @@ final class ServerSelectionCoordinator: Coordinator, Presentable { // Must be used only internally var childCoordinators: [Coordinator] = [] - var callback: (@MainActor (ServerSelectionCoordinatorAction) -> Void)? + var callback: (@MainActor(ServerSelectionCoordinatorAction) -> Void)? // MARK: - Setup diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionModels.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionModels.swift index 93c6265c6..cf84e2b7f 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionModels.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModel.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModel.swift index d20d8da05..fc0570e03 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModel.swift @@ -26,7 +26,7 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie // MARK: Public - var callback: (@MainActor (ServerSelectionViewModelAction) -> Void)? + var callback: (@MainActor(ServerSelectionViewModelAction) -> Void)? // MARK: - Setup diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModelProtocol.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModelProtocol.swift index 1235abe1f..63e15a75e 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModelProtocol.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ import Foundation @MainActor protocol ServerSelectionViewModelProtocol { - var callback: (@MainActor (ServerSelectionViewModelAction) -> Void)? { get set } + var callback: (@MainActor(ServerSelectionViewModelAction) -> Void)? { get set } var context: ServerSelectionViewModelType.Context { get } /// Displays an error to the user. diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/View/ServerSelectionScreen.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/View/ServerSelectionScreen.swift index ffa06b6ad..469fdb657 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/View/ServerSelectionScreen.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/View/ServerSelectionScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Authentication/UIConstants.swift b/ElementX/Sources/Screens/Authentication/UIConstants.swift index b15db271a..d00c8ad36 100644 --- a/ElementX/Sources/Screens/Authentication/UIConstants.swift +++ b/ElementX/Sources/Screens/Authentication/UIConstants.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/BugReport/BugReportModels.swift b/ElementX/Sources/Screens/BugReport/BugReportModels.swift index a23b129bf..1c8d9bc3f 100644 --- a/ElementX/Sources/Screens/BugReport/BugReportModels.swift +++ b/ElementX/Sources/Screens/BugReport/BugReportModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/BugReport/BugReportViewModel.swift b/ElementX/Sources/Screens/BugReport/BugReportViewModel.swift index 73e62e991..cd6516420 100644 --- a/ElementX/Sources/Screens/BugReport/BugReportViewModel.swift +++ b/ElementX/Sources/Screens/BugReport/BugReportViewModel.swift @@ -18,7 +18,7 @@ import SwiftUI @available(iOS 14, *) typealias BugReportViewModelType = StateStoreViewModel + BugReportViewAction> @available(iOS 14, *) class BugReportViewModel: BugReportViewModelType, BugReportViewModelProtocol { @@ -50,7 +50,7 @@ class BugReportViewModel: BugReportViewModelType, BugReportViewModelProtocol { files: files) MXLog.info("[BugReportViewModel] submitBugReport succeeded, result: \(result.reportUrl)") callback?(.submitFinished) - } catch let error { + } catch { MXLog.error("[BugReportViewModel] submitBugReport failed: \(error)") callback?(.submitFailed(error: error)) } diff --git a/ElementX/Sources/Screens/BugReport/BugReportViewModelProtocol.swift b/ElementX/Sources/Screens/BugReport/BugReportViewModelProtocol.swift index 906444ae9..48f5a1d7d 100644 --- a/ElementX/Sources/Screens/BugReport/BugReportViewModelProtocol.swift +++ b/ElementX/Sources/Screens/BugReport/BugReportViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/BugReport/View/BugReportScreen.swift b/ElementX/Sources/Screens/BugReport/View/BugReportScreen.swift index 79f4a377d..6e60ff538 100644 --- a/ElementX/Sources/Screens/BugReport/View/BugReportScreen.swift +++ b/ElementX/Sources/Screens/BugReport/View/BugReportScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift index e594e8674..3a3a78c4b 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import Combine +import SwiftUI struct HomeScreenCoordinatorParameters { let userSession: UserSessionProtocol @@ -108,12 +108,11 @@ final class HomeScreenCoordinator: Coordinator, Presentable { } // MARK: - Public - func start() { - - } + + func start() { } func toPresentable() -> UIViewController { - return self.hostingController + hostingController } // MARK: - Private diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift index 745ea10c1..c9691c095 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,14 +34,14 @@ struct HomeScreenViewState: BindableState { var userDisplayName: String? var userAvatar: UIImage? - var showSessionVerificationBanner: Bool = false + var showSessionVerificationBanner = false var rooms: [HomeScreenRoom] = [] - var isLoadingRooms: Bool = false + var isLoadingRooms = false var visibleDMs: [HomeScreenRoom] { - searchFilteredRooms.filter { $0.isDirect } + searchFilteredRooms.filter(\.isDirect) } var visibleRooms: [HomeScreenRoom] { @@ -62,7 +62,7 @@ struct HomeScreenViewState: BindableState { } struct HomeScreenViewStateBindings { - var searchQuery: String = "" + var searchQuery = "" } struct HomeScreenRoom: Identifiable, Equatable { diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index f208b4699..0d325ba6a 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import Combine +import SwiftUI typealias HomeScreenViewModelType = StateStoreViewModel @@ -65,7 +65,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol roomUpdateListeners.removeAll() - roomSummaries.forEach({ roomSummary in + roomSummaries.forEach { roomSummary in roomSummary.callbacks .receive(on: DispatchQueue.main) .sink { [weak self] callback in @@ -81,7 +81,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol } } .store(in: &roomUpdateListeners) - }) + } } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModelProtocol.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModelProtocol.swift index 0cbc97a18..d45a39d9c 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModelProtocol.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index 208c208e9..57535a127 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -167,7 +167,7 @@ struct RoomCell: View { } private func roomName(_ room: HomeScreenRoom) -> String { - room.displayName ?? room.id + (room.isEncrypted ? "🛡": "") + room.displayName ?? room.id + (room.isEncrypted ? "🛡" : "") } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index af7c7aea6..5b49e4e00 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -55,11 +55,10 @@ final class RoomScreenCoordinator: Coordinator, Presentable { } // MARK: - Public - func start() { - - } + + func start() { } func toPresentable() -> UIViewController { - return self.roomScreenHostingController + roomScreenHostingController } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 0d32c68d4..4364c384e 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,7 @@ import Foundation import UIKit -enum RoomScreenViewModelAction { - -} +enum RoomScreenViewModelAction { } enum TimelineItemContextMenuAction: Hashable { case copy @@ -35,14 +33,14 @@ enum RoomScreenViewAction { } struct RoomScreenViewState: BindableState { - var roomTitle: String = "" + var roomTitle = "" var roomAvatar: UIImage? var roomEncryptionBadge: UIImage? var items: [RoomTimelineViewProvider] = [] var isBackPaginating = false var bindings: RoomScreenViewStateBindings - var contextMenuBuilder: (@MainActor (_ itemId: String) -> TimelineItemContextMenu)? + var contextMenuBuilder: (@MainActor(_ itemId: String) -> TimelineItemContextMenu)? var sendButtonDisabled: Bool { bindings.composerText.count == 0 diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 5a5204550..fbddfc7fe 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -20,7 +20,7 @@ typealias RoomScreenViewModelType = StateStoreViewModel TimelineItemContextMenu { - TimelineItemContextMenu(contextMenuActions: self.contextMenuActionsForItemId(itemId)) { [weak self] action in + TimelineItemContextMenu(contextMenuActions: contextMenuActionsForItemId(itemId)) { [weak self] action in self?.processContentMenuAction(action, itemId: itemId) } } private func contextMenuActionsForItemId(_ itemId: String) -> [TimelineItemContextMenuAction] { - guard let timelineItem = self.timelineController.timelineItems.first(where: { $0.id == itemId }), + guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemId }), timelineItem is EventBasedTimelineItemProtocol else { return [] } @@ -121,7 +121,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol } private func processContentMenuAction(_ action: TimelineItemContextMenuAction, itemId: String) { - guard let timelineItem = self.timelineController.timelineItems.first(where: { $0.id == itemId }), + guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemId }), let item = timelineItem as? EventBasedTimelineItemProtocol else { return } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift index 73874fc8e..e9f30dafc 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/RoomScreen/View/ListTableViewAdapter.swift b/ElementX/Sources/Screens/RoomScreen/View/ListTableViewAdapter.swift index 8a30a2c04..8a5ba31be 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/ListTableViewAdapter.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/ListTableViewAdapter.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Combine +import UIKit class ListTableViewAdapter: NSObject, UITableViewDelegate { @@ -79,8 +79,8 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate { } guard let tableView = tableView, - tableView.numberOfSections > 0 else { - return + tableView.numberOfSections > 0 else { + return } let currentItemCount = tableView.numberOfRows(inSection: 0) @@ -89,7 +89,7 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate { case .bottomOffset: tableView.scrollToRow(at: .init(row: max(0, currentItemCount - 1), section: 0), at: .bottom, animated: false) case .topOffset(let indexPath, let previousItemCount): - let row = indexPath.row + max(0, (currentItemCount - previousItemCount)) + let row = indexPath.row + max(0, currentItemCount - previousItemCount) if row < currentItemCount { tableView.scrollToRow(at: .init(row: row, section: 0), at: .top, animated: false) } @@ -108,8 +108,8 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate { func scrollToBottom(animated: Bool = false) { guard let tableView = tableView, - tableView.numberOfSections > 0 else { - return + tableView.numberOfSections > 0 else { + return } let currentItemCount = tableView.numberOfRows(inSection: 0) @@ -180,9 +180,9 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate { scrollViewBottomVisiblePublisher.send(isBottomVisible) } - if !draggingInitiated && tableView.isDragging { + if !draggingInitiated, tableView.isDragging { draggingInitiated = true - } else if draggingInitiated && !tableView.isDragging { + } else if draggingInitiated, !tableView.isDragging { draggingInitiated = false scrollViewDidRestPublisher.send(()) } @@ -193,7 +193,7 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate { sender.state == .ended, draggingInitiated == true, !tableView.isDecelerating else { - return + return } draggingInitiated = false diff --git a/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift b/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift index 6a2b2535d..f11bcf312 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift @@ -23,7 +23,7 @@ struct MessageComposerTextField: View { init(placeholder: String, text: Binding, maxHeight: CGFloat) { self.placeholder = placeholder - self._text = text + _text = text self.maxHeight = maxHeight } @@ -36,7 +36,7 @@ struct MessageComposerTextField: View { } private var borderWidth: CGFloat { - return isEditing ? 2.0 : 1.0 + isEditing ? 2.0 : 1.0 } var body: some View { @@ -89,18 +89,18 @@ private struct UITextViewWrapper: UIViewRepresentable { } func updateUIView(_ view: UITextView, context: UIViewRepresentableContext) { - if view.text != self.text { - view.text = self.text + if view.text != text { + view.text = text } UITextViewWrapper.recalculateHeight(view: view, result: $calculatedHeight, maxHeight: maxHeight) } func makeCoordinator() -> Coordinator { - return Coordinator(text: $text, - height: $calculatedHeight, - isEditing: $isEditing, - maxHeight: maxHeight) + Coordinator(text: $text, + height: $calculatedHeight, + isEditing: $isEditing, + maxHeight: maxHeight) } fileprivate static func recalculateHeight(view: UIView, result: Binding, maxHeight: CGFloat) { @@ -124,7 +124,7 @@ private struct UITextViewWrapper: UIViewRepresentable { init(text: Binding, height: Binding, isEditing: Binding, maxHeight: CGFloat) { self.text = text - self.calculatedHeight = height + calculatedHeight = height self.isEditing = isEditing self.maxHeight = maxHeight } @@ -137,7 +137,7 @@ private struct UITextViewWrapper: UIViewRepresentable { } func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { - return true + true } func textViewDidBeginEditing(_ textView: UITextView) { diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomHeaderView.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomHeaderView.swift index 8a258abcb..900c0c077 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomHeaderView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomHeaderView.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import SwiftUI -import Combine import Introspect @@ -65,8 +65,7 @@ struct RoomHeaderView_Previews: PreviewProvider { let viewModel = RoomScreenViewModel(timelineController: MockRoomTimelineController(), timelineViewFactory: RoomTimelineViewFactory(), roomName: "Some Room name", - roomAvatar: Asset.Images.appLogo.image - ) + roomAvatar: Asset.Images.appLogo.image) RoomHeaderView(context: viewModel.context) .previewLayout(.sizeThatFits) @@ -79,8 +78,7 @@ struct RoomHeaderView_Previews: PreviewProvider { timelineViewFactory: RoomTimelineViewFactory(), roomName: "Some Room name", roomAvatar: nil, - roomEncryptionBadge: Asset.Images.encryptionTrusted.image - ) + roomEncryptionBadge: Asset.Images.encryptionTrusted.image) RoomHeaderView(context: viewModel.context) .previewLayout(.sizeThatFits) diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index 7e6137843..d13095d54 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift index b4cc8e492..a891bd2a8 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift @@ -89,7 +89,7 @@ struct TimelineItemBubbledStylerView: View { } private var shouldAvoidBubbling: Bool { - return timelineItem is ImageRoomTimelineItem + timelineItem is ImageRoomTimelineItem } private var bubbleColor: Color { @@ -108,7 +108,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider { @ViewBuilder static var body: some View { VStack(alignment: .leading) { - ForEach((1.. EmoteRoomTimelineItem { - return EmoteRoomTimelineItem(id: UUID().uuidString, - text: text, - timestamp: timestamp, - shouldShowSenderDetails: true, - isOutgoing: false, - senderId: senderId) + EmoteRoomTimelineItem(id: UUID().uuidString, + text: text, + timestamp: timestamp, + shouldShowSenderDetails: true, + isOutgoing: false, + senderId: senderId) } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift index 1d1dc6732..9c62ecafd 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift @@ -45,25 +45,26 @@ struct FormattedBodyText_Previews: PreviewProvider { @ViewBuilder static var body: some View { let htmlStrings = [ -""" -Text before blockquote -
-bold italic -
-Text after blockquote -""", -""" -
First blockquote with a link in it
-
Second blockquote with a link in it
-
Third blockquote with a link in it
-""", -""" -Hello world -

Text

-Hello world -

Text

-Hello world -"""] + """ + Text before blockquote +
+ bold italic +
+ Text after blockquote + """, + """ +
First blockquote with a link in it
+
Second blockquote with a link in it
+
Third blockquote with a link in it
+ """, + """ + Hello world +

Text

+ Hello world +

Text

+ Hello world + """ + ] let attributedStringBuilder = AttributedStringBuilder() VStack(alignment: .leading, spacing: 24.0) { diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/NoticeRoomTimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/NoticeRoomTimelineView.swift index f67ea31b2..1f4ce87b0 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/NoticeRoomTimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/NoticeRoomTimelineView.swift @@ -49,11 +49,11 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider { } private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem { - return NoticeRoomTimelineItem(id: UUID().uuidString, - text: text, - timestamp: timestamp, - shouldShowSenderDetails: true, - isOutgoing: false, - senderId: senderId) + NoticeRoomTimelineItem(id: UUID().uuidString, + text: text, + timestamp: timestamp, + shouldShowSenderDetails: true, + isOutgoing: false, + senderId: senderId) } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift index e36e79492..67c31c27f 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2022 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/TextRoomTimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/TextRoomTimelineView.swift index 23c30b9bf..93f7cd7c4 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/TextRoomTimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/TextRoomTimelineView.swift @@ -52,24 +52,24 @@ struct TextRoomTimelineView_Previews: PreviewProvider { shouldShowSenderDetails: true, isOutgoing: false, senderId: "Bob")) - .timelineStyle(.plain) + .timelineStyle(.plain) TextRoomTimelineView(timelineItem: itemWith(text: "Some other text", timestamp: "Later", shouldShowSenderDetails: true, isOutgoing: true, senderId: "Anne")) - .timelineStyle(.plain) + .timelineStyle(.plain) } .padding(.horizontal, 8) } private static func itemWith(text: String, timestamp: String, shouldShowSenderDetails: Bool, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem { - return TextRoomTimelineItem(id: UUID().uuidString, - text: text, - timestamp: timestamp, - shouldShowSenderDetails: shouldShowSenderDetails, - isOutgoing: isOutgoing, - senderId: senderId) + TextRoomTimelineItem(id: UUID().uuidString, + text: text, + timestamp: timestamp, + shouldShowSenderDetails: shouldShowSenderDetails, + isOutgoing: isOutgoing, + senderId: senderId) } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift index 94eff16c4..744f3972e 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemList.swift @@ -6,13 +6,13 @@ // Copyright © 2022 Element. All rights reserved. // -import SwiftUI import Combine import Introspect +import SwiftUI struct TimelineItemList: View { - @State private var tableViewObserver: ListTableViewAdapter = ListTableViewAdapter() + @State private var tableViewObserver = ListTableViewAdapter() @State private var timelineItems: [RoomTimelineViewProvider] = [] @State private var hasPendingChanges = false @ObservedObject private var settings = ElementSettings.shared @@ -65,7 +65,7 @@ struct TimelineItemList: View { } tableViewObserver = ListTableViewAdapter(tableView: tableView, - topDetectionOffset: (tableView.bounds.size.height / 3.0), + topDetectionOffset: tableView.bounds.size.height / 3.0, bottomDetectionOffset: 10.0) tableViewObserver.scrollToBottom() @@ -136,11 +136,11 @@ struct TimelineItemList: View { } private var isPreview: Bool { -#if DEBUG + #if DEBUG return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" -#else + #else return false -#endif + #endif } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineView.swift index b864eee52..544c2fe9d 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineView.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import SwiftUI -import Combine import Introspect diff --git a/ElementX/Sources/Screens/SessionVerification/SessionVerificationModels.swift b/ElementX/Sources/Screens/SessionVerification/SessionVerificationModels.swift index 5ad69e5d3..6b3b5e838 100644 --- a/ElementX/Sources/Screens/SessionVerification/SessionVerificationModels.swift +++ b/ElementX/Sources/Screens/SessionVerification/SessionVerificationModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/SessionVerification/SessionVerificationStateMachine.swift b/ElementX/Sources/Screens/SessionVerification/SessionVerificationStateMachine.swift index 005bb6189..27ab20140 100644 --- a/ElementX/Sources/Screens/SessionVerification/SessionVerificationStateMachine.swift +++ b/ElementX/Sources/Screens/SessionVerification/SessionVerificationStateMachine.swift @@ -61,20 +61,20 @@ class SessionVerificationStateMachine { // swiftlint:disable cyclomatic_complexity init() { stateMachine = StateMachine(state: .initial) { machine in - machine.addRoutes(event: .requestVerification, transitions: [ .initial => .requestingVerification ]) - machine.addRoutes(event: .didFail, transitions: [ .requestingVerification => .initial ]) + machine.addRoutes(event: .requestVerification, transitions: [.initial => .requestingVerification]) + machine.addRoutes(event: .didFail, transitions: [.requestingVerification => .initial]) - machine.addRoutes(event: .cancel, transitions: [ .requestingVerification => .cancelling ]) - machine.addRoutes(event: .didCancel, transitions: [ .requestingVerification => .cancelled ]) + machine.addRoutes(event: .cancel, transitions: [.requestingVerification => .cancelling]) + machine.addRoutes(event: .didCancel, transitions: [.requestingVerification => .cancelled]) // Cancellation request from the other party should either take us from `.cancelling` // to `.cancelled` or keep us in `.cancelled` if already there. There is more `.didCancel` // handling in `addRouteMapping` for states containing associated values - machine.addRoutes(event: .didCancel, transitions: [ .cancelling => .cancelled ]) - machine.addRoutes(event: .didCancel, transitions: [ .cancelled => .cancelled ]) - machine.addRoutes(event: .didFail, transitions: [ .cancelled => .cancelled ]) + machine.addRoutes(event: .didCancel, transitions: [.cancelling => .cancelled]) + machine.addRoutes(event: .didCancel, transitions: [.cancelled => .cancelled]) + machine.addRoutes(event: .didFail, transitions: [.cancelled => .cancelled]) - machine.addRoutes(event: .restart, transitions: [ .cancelled => .initial ]) + machine.addRoutes(event: .restart, transitions: [.cancelled => .initial]) // Transitions with associated values need to be handled through `addRouteMapping` machine.addRouteMapping { event, fromState, _ in @@ -115,6 +115,7 @@ class SessionVerificationStateMachine { } } } + // swiftlint:enable cyclomatic_complexity /// Attempt to move the state machine to another state through an event diff --git a/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModel.swift b/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModel.swift index e6ae2f917..89d6a3ad0 100644 --- a/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModel.swift +++ b/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModel.swift @@ -75,8 +75,8 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer callback?(.finished) case .cancel: guard stateMachine.state == .initial || - stateMachine.state == .verified || - stateMachine.state == .cancelled else { + stateMachine.state == .verified || + stateMachine.state == .cancelled else { stateMachine.processEvent(.cancel) return } @@ -119,7 +119,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer private func requestVerification() { Task { switch await sessionVerificationControllerProxy.requestVerification() { - case.success: + case .success: // Need to wait for the callback from the remote break case .failure: @@ -131,7 +131,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer private func cancelVerification() { Task { switch await sessionVerificationControllerProxy.cancelVerification() { - case.success: + case .success: stateMachine.processEvent(.didCancel) case .failure: stateMachine.processEvent(.didFail) @@ -142,7 +142,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer private func acceptChallenge() { Task { switch await sessionVerificationControllerProxy.approveVerification() { - case.success: + case .success: // Need to wait for the callback from the remote break case .failure: @@ -154,7 +154,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer private func declineChallenge() { Task { switch await sessionVerificationControllerProxy.declineVerification() { - case.success: + case .success: stateMachine.processEvent(.didCancel) case .failure: stateMachine.processEvent(.didFail) diff --git a/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModelProtocol.swift b/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModelProtocol.swift index 0877d2ab2..781e1c2e7 100644 --- a/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModelProtocol.swift +++ b/ElementX/Sources/Screens/SessionVerification/SessionVerificationViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/SessionVerification/View/SessionVerificationScreen.swift b/ElementX/Sources/Screens/SessionVerification/View/SessionVerificationScreen.swift index 2ff529325..75ffdc2cd 100644 --- a/ElementX/Sources/Screens/SessionVerification/View/SessionVerificationScreen.swift +++ b/ElementX/Sources/Screens/SessionVerification/View/SessionVerificationScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import MatrixRustSDK +import SwiftUI struct SessionVerificationScreen: View { diff --git a/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift b/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift index 72d2f46f0..14aa6ae1d 100644 --- a/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift @@ -109,7 +109,7 @@ final class SettingsCoordinator: Coordinator, Presentable { add(childCoordinator: coordinator) coordinator.start() - self.parameters.navigationRouter.push(coordinator, animated: true) { [weak self] in + parameters.navigationRouter.push(coordinator, animated: true) { [weak self] in guard let self = self else { return } self.remove(childCoordinator: coordinator) diff --git a/ElementX/Sources/Screens/Settings/SettingsModels.swift b/ElementX/Sources/Screens/Settings/SettingsModels.swift index ee83d1f5e..d0b2d5c35 100644 --- a/ElementX/Sources/Screens/Settings/SettingsModels.swift +++ b/ElementX/Sources/Screens/Settings/SettingsModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,9 +32,7 @@ struct SettingsViewState: BindableState { var bindings: SettingsViewStateBindings } -struct SettingsViewStateBindings { - -} +struct SettingsViewStateBindings { } enum SettingsViewAction { case reportBug diff --git a/ElementX/Sources/Screens/Settings/SettingsViewModel.swift b/ElementX/Sources/Screens/Settings/SettingsViewModel.swift index 0fe113863..825c0687c 100644 --- a/ElementX/Sources/Screens/Settings/SettingsViewModel.swift +++ b/ElementX/Sources/Screens/Settings/SettingsViewModel.swift @@ -18,7 +18,7 @@ import SwiftUI @available(iOS 14, *) typealias SettingsViewModelType = StateStoreViewModel + SettingsViewAction> @available(iOS 14, *) class SettingsViewModel: SettingsViewModelType, SettingsViewModelProtocol { diff --git a/ElementX/Sources/Screens/Settings/SettingsViewModelProtocol.swift b/ElementX/Sources/Screens/Settings/SettingsViewModelProtocol.swift index ef1de01bb..87d69ca9d 100644 --- a/ElementX/Sources/Screens/Settings/SettingsViewModelProtocol.swift +++ b/ElementX/Sources/Screens/Settings/SettingsViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/Settings/View/SettingsScreen.swift b/ElementX/Sources/Screens/Settings/View/SettingsScreen.swift index 40aed7416..e5a004ad7 100644 --- a/ElementX/Sources/Screens/Settings/View/SettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/View/SettingsScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,7 +44,7 @@ struct SettingsScreen: View { role: .destructive) { context.send(viewAction: .crash) } - .accessibilityIdentifier("crashButton") + .accessibilityIdentifier("crashButton") } } .listRowBackground(rowBackgroundColor) diff --git a/ElementX/Sources/Screens/Splash/SplashViewController.swift b/ElementX/Sources/Screens/Splash/SplashViewController.swift index 59e3377f4..152dbecc3 100644 --- a/ElementX/Sources/Screens/Splash/SplashViewController.swift +++ b/ElementX/Sources/Screens/Splash/SplashViewController.swift @@ -8,6 +8,4 @@ import UIKit -class SplashViewController: UIViewController { - -} +class SplashViewController: UIViewController { } diff --git a/ElementX/Sources/Screens/SplashScreen/SplashScreenCoordinator.swift b/ElementX/Sources/Screens/SplashScreen/SplashScreenCoordinator.swift index d683f7be5..bf23edb4c 100644 --- a/ElementX/Sources/Screens/SplashScreen/SplashScreenCoordinator.swift +++ b/ElementX/Sources/Screens/SplashScreen/SplashScreenCoordinator.swift @@ -46,6 +46,7 @@ final class SplashScreenCoordinator: Coordinator, Presentable { } // MARK: - Public + func start() { MXLog.debug("[SplashScreenCoordinator] did start.") splashScreenViewModel.callback = { [weak self] action in @@ -59,7 +60,7 @@ final class SplashScreenCoordinator: Coordinator, Presentable { } func toPresentable() -> UIViewController { - return splashScreenHostingController + splashScreenHostingController } /// Stops any ongoing activities in the coordinator. diff --git a/ElementX/Sources/Screens/SplashScreen/SplashScreenModels.swift b/ElementX/Sources/Screens/SplashScreen/SplashScreenModels.swift index fc8c7c068..297aefccc 100644 --- a/ElementX/Sources/Screens/SplashScreen/SplashScreenModels.swift +++ b/ElementX/Sources/Screens/SplashScreen/SplashScreenModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/SplashScreen/SplashScreenViewModel.swift b/ElementX/Sources/Screens/SplashScreen/SplashScreenViewModel.swift index ae4a54b24..4c4b070c8 100644 --- a/ElementX/Sources/Screens/SplashScreen/SplashScreenViewModel.swift +++ b/ElementX/Sources/Screens/SplashScreen/SplashScreenViewModel.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import Combine +import SwiftUI typealias SplashScreenViewModelType = StateStoreViewModel diff --git a/ElementX/Sources/Screens/SplashScreen/View/SplashScreen.swift b/ElementX/Sources/Screens/SplashScreen/View/SplashScreen.swift index eaefdb009..408d699d8 100644 --- a/ElementX/Sources/Screens/SplashScreen/View/SplashScreen.swift +++ b/ElementX/Sources/Screens/SplashScreen/View/SplashScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,8 @@ // limitations under the License. // -import SwiftUI import DesignKit +import SwiftUI /// The splash screen shown at the beginning of the onboarding flow. struct SplashScreen: View { @@ -152,7 +152,7 @@ struct SplashScreen: View { private func showPreviousPage() { // Prevent the hidden page at index -1 from being shown. - context.pageIndex = max(0, (context.pageIndex - 1)) + context.pageIndex = max(0, context.pageIndex - 1) } private func showHiddenPage() { diff --git a/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageIndicator.swift b/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageIndicator.swift index 113de33d2..d6fe83d1e 100644 --- a/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageIndicator.swift +++ b/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageIndicator.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageView.swift b/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageView.swift index b40f21749..f4f7cac02 100644 --- a/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageView.swift +++ b/ElementX/Sources/Screens/SplashScreen/View/SplashScreenPageView.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,8 +33,8 @@ struct SplashScreenPageView: View { .resizable() .scaledToFit() .frame(maxWidth: 310) // This value is problematic. 300 results in dropped frames - // on iPhone 12/13 Mini. 305 the same on iPhone 12/13. As of - // iOS 15, 310 seems fine on all supported screen widths 🤞. + // on iPhone 12/13 Mini. 305 the same on iPhone 12/13. As of + // iOS 15, 310 seems fine on all supported screen widths 🤞. .padding(20) .accessibilityHidden(true) diff --git a/ElementX/Sources/Services/Authentication/AuthenticationService.swift b/ElementX/Sources/Services/Authentication/AuthenticationService.swift index cd7257038..7f53a5f56 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationService.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationService.swift @@ -15,7 +15,7 @@ class AuthenticationService: AuthenticationServiceProtocol { // MARK: Private - private(set) var homeserver: LoginHomeserver = LoginHomeserver(address: BuildSettings.defaultHomeserverURLString) + private(set) var homeserver = LoginHomeserver(address: BuildSettings.defaultHomeserverURLString) private let userSessionStore: UserSessionStoreProtocol // MARK: - Setup diff --git a/ElementX/Sources/Services/Background/ApplicationProtocol.swift b/ElementX/Sources/Services/Background/ApplicationProtocol.swift index 149dbe780..a194ed1b6 100644 --- a/ElementX/Sources/Services/Background/ApplicationProtocol.swift +++ b/ElementX/Sources/Services/Background/ApplicationProtocol.swift @@ -21,4 +21,4 @@ protocol ApplicationProtocol { var applicationState: UIApplication.State { get } } -extension UIApplication: ApplicationProtocol {} +extension UIApplication: ApplicationProtocol { } diff --git a/ElementX/Sources/Services/Background/BackgroundTaskServiceProtocol.swift b/ElementX/Sources/Services/Background/BackgroundTaskServiceProtocol.swift index 76e1fde01..3988f1183 100644 --- a/ElementX/Sources/Services/Background/BackgroundTaskServiceProtocol.swift +++ b/ElementX/Sources/Services/Background/BackgroundTaskServiceProtocol.swift @@ -19,22 +19,22 @@ protocol BackgroundTaskServiceProtocol { extension BackgroundTaskServiceProtocol { func startBackgroundTask(withName name: String) -> BackgroundTaskProtocol? { - return startBackgroundTask(withName: name, - expirationHandler: nil) + startBackgroundTask(withName: name, + expirationHandler: nil) } func startBackgroundTask(withName name: String, isReusable: Bool) -> BackgroundTaskProtocol? { - return startBackgroundTask(withName: name, - isReusable: isReusable, - expirationHandler: nil) + startBackgroundTask(withName: name, + isReusable: isReusable, + expirationHandler: nil) } func startBackgroundTask(withName name: String, expirationHandler: (() -> Void)?) -> BackgroundTaskProtocol? { - return startBackgroundTask(withName: name, - isReusable: false, - expirationHandler: expirationHandler) + startBackgroundTask(withName: name, + isReusable: false, + expirationHandler: expirationHandler) } } diff --git a/ElementX/Sources/Services/Background/UIKitBackgroundTask.swift b/ElementX/Sources/Services/Background/UIKitBackgroundTask.swift index 89a05457b..cf0e21412 100644 --- a/ElementX/Sources/Services/Background/UIKitBackgroundTask.swift +++ b/ElementX/Sources/Services/Background/UIKitBackgroundTask.swift @@ -15,16 +15,17 @@ class UIKitBackgroundTask: BackgroundTaskProtocol { var isRunning: Bool { identifier != .invalid } + let isReusable: Bool let expirationHandler: BackgroundTaskExpirationHandler? var elapsedTime: TimeInterval { - return Date().timeIntervalSince(startDate) * 1000 + Date().timeIntervalSince(startDate) * 1000 } private let application: ApplicationProtocol private var identifier: UIBackgroundTaskIdentifier = .invalid - private var useCounter: Int = 0 - private let startDate: Date = Date() + private var useCounter = 0 + private let startDate = Date() /// Initializes and starts a new background task /// - Parameters: diff --git a/ElementX/Sources/Services/Background/UIKitBackgroundTaskService.swift b/ElementX/Sources/Services/Background/UIKitBackgroundTaskService.swift index b9e2069bc..eed6e995b 100644 --- a/ElementX/Sources/Services/Background/UIKitBackgroundTaskService.swift +++ b/ElementX/Sources/Services/Background/UIKitBackgroundTaskService.swift @@ -35,7 +35,7 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol { expirationHandler?() return nil } - var created: Bool = false + var created = false var result: BackgroundTaskProtocol? if isReusable { @@ -47,10 +47,10 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol { isReusable: isReusable, application: application, expirationHandler: { [weak self] task in - guard let self = self else { return } - self.reusableTasks[task.name] = nil - expirationHandler?() - }) { + guard let self = self else { return } + self.reusableTasks[task.name] = nil + expirationHandler?() + }) { created = true reusableTasks[name] = newTask result = newTask @@ -61,8 +61,8 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol { isReusable: isReusable, application: application, expirationHandler: { _ in - expirationHandler?() - }) { + expirationHandler?() + }) { result = newTask created = true } @@ -85,8 +85,8 @@ class UIKitBackgroundTaskService: BackgroundTaskServiceProtocol { } private func avoidStartingNewTasks(for application: ApplicationProtocol) -> Bool { - if application.applicationState == .background - && application.backgroundTimeRemaining < .backgroundTimeRemainingThresholdToStartTasks { + if application.applicationState == .background, + application.backgroundTimeRemaining < .backgroundTimeRemainingThresholdToStartTasks { return true } return false diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index fa66a82ce..ebc1d6232 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -7,10 +7,10 @@ // import Foundation -import MatrixRustSDK -import UIKit import GZIP +import MatrixRustSDK import Sentry +import UIKit enum BugReportServiceError: Error { case invalidBaseUrlString @@ -33,7 +33,7 @@ class BugReportService: BugReportServiceProtocol { guard !sentryEndpoint.isEmpty else { throw BugReportServiceError.invalidSentryEndpoint } - self.baseURL = url + baseURL = url self.sentryEndpoint = sentryEndpoint self.applicationId = applicationId self.session = session @@ -69,7 +69,7 @@ class BugReportService: BugReportServiceProtocol { // MARK: - BugReportServiceProtocol var crashedLastRun: Bool { - return SentrySDK.crashedLastRun + SentrySDK.crashedLastRun } func crash() { @@ -182,8 +182,8 @@ class BugReportService: BugReportServiceProtocol { filesToCompress.append(URL(fileURLWithPath: crashLogFile)) } - var totalSize: Int = 0 - var totalZippedSize: Int = 0 + var totalSize = 0 + var totalZippedSize = 0 var zippedFiles: [URL] = [] for url in filesToCompress { diff --git a/ElementX/Sources/Services/BugReport/MockBugReportService.swift b/ElementX/Sources/Services/BugReport/MockBugReportService.swift index 4cc5beddc..2ca33f668 100644 --- a/ElementX/Sources/Services/BugReport/MockBugReportService.swift +++ b/ElementX/Sources/Services/BugReport/MockBugReportService.swift @@ -16,10 +16,10 @@ class MockBugReportService: BugReportServiceProtocol { includeCrashLog: Bool, githubLabels: [String], files: [URL]) async throws -> SubmitBugReportResponse { - return SubmitBugReportResponse(reportUrl: "https://www.example/com/123") + SubmitBugReportResponse(reportUrl: "https://www.example/com/123") } - var crashedLastRun: Bool = false + var crashedLastRun = false func crash() { // no-op diff --git a/ElementX/Sources/Services/BugReport/ScreenshotDetector.swift b/ElementX/Sources/Services/BugReport/ScreenshotDetector.swift index 0c2143549..d22b454a7 100644 --- a/ElementX/Sources/Services/BugReport/ScreenshotDetector.swift +++ b/ElementX/Sources/Services/BugReport/ScreenshotDetector.swift @@ -7,8 +7,8 @@ // import Foundation -import UIKit import Photos +import UIKit enum ScreenshotDetectorError: String, Error { case loadFailed @@ -18,7 +18,7 @@ enum ScreenshotDetectorError: String, Error { @MainActor class ScreenshotDetector { - var callback: (@MainActor (UIImage?, Error?) -> Void)? + var callback: (@MainActor(UIImage?, Error?) -> Void)? /// Flag to whether ask for photos authorization by default if needed. var autoRequestPHAuthorization = true @@ -38,7 +38,7 @@ class ScreenshotDetector { let authStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite) if authStatus == .authorized { findScreenshot() - } else if authStatus == .notDetermined && autoRequestPHAuthorization { + } else if authStatus == .notDetermined, autoRequestPHAuthorization { Task { self.handleAuthStatus(await PHPhotoLibrary.requestAuthorization(for: .readWrite)) } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index b3019fd65..25e3643b2 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import MatrixRustSDK -import Combine import UIKit private class WeakClientProxyWrapper: ClientDelegate { @@ -128,7 +128,7 @@ class ClientProxy: ClientProxyProtocol { Benchmark.endTrackingForIdentifier("ClientRooms", message: "Retrieved \(sdkRooms.count) rooms") Benchmark.startTrackingForIdentifier("ProcessingRooms", message: "Started processing \(sdkRooms.count) rooms") - let diff = sdkRooms.map({ $0.id() }).difference(from: currentRooms.map(\.id)) + let diff = sdkRooms.map { $0.id() }.difference(from: currentRooms.map(\.id)) for change in diff { switch change { diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 17b543c55..41e86ee94 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import MatrixRustSDK -import Combine enum ClientProxyCallback { case updatedRoomsList diff --git a/ElementX/Sources/Services/Media/MediaProvider.swift b/ElementX/Sources/Services/Media/MediaProvider.swift index 988024981..86ad7e124 100644 --- a/ElementX/Sources/Services/Media/MediaProvider.swift +++ b/ElementX/Sources/Services/Media/MediaProvider.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Kingfisher +import UIKit struct MediaProvider: MediaProviderProtocol { private let clientProxy: ClientProxyProtocol @@ -21,7 +21,7 @@ struct MediaProvider: MediaProviderProtocol { self.clientProxy = clientProxy self.imageCache = imageCache self.backgroundTaskService = backgroundTaskService - self.processingQueue = DispatchQueue(label: "MediaProviderProcessingQueue", attributes: .concurrent) + processingQueue = DispatchQueue(label: "MediaProviderProcessingQueue", attributes: .concurrent) } func imageFromSource(_ source: MediaSource?) -> UIImage? { diff --git a/ElementX/Sources/Services/Media/MediaSource.swift b/ElementX/Sources/Services/Media/MediaSource.swift index 44e0cfd32..4dc753f7a 100644 --- a/ElementX/Sources/Services/Media/MediaSource.swift +++ b/ElementX/Sources/Services/Media/MediaSource.swift @@ -23,6 +23,6 @@ struct MediaSource: Equatable { // MARK: - Equatable static func == (lhs: MediaSource, rhs: MediaSource) -> Bool { - return lhs.underlyingSource.url() == rhs.underlyingSource.url() + lhs.underlyingSource.url() == rhs.underlyingSource.url() } } diff --git a/ElementX/Sources/Services/Media/MockMediaProvider.swift b/ElementX/Sources/Services/Media/MockMediaProvider.swift index ae85cbe49..ecb859faf 100644 --- a/ElementX/Sources/Services/Media/MockMediaProvider.swift +++ b/ElementX/Sources/Services/Media/MockMediaProvider.swift @@ -12,18 +12,18 @@ import UIKit struct MockMediaProvider: MediaProviderProtocol { func imageFromSource(_ source: MediaSource?) -> UIImage? { - return nil + nil } func loadImageFromSource(_ source: MediaSource) async -> Result { - return .failure(.failedRetrievingImage) + .failure(.failedRetrievingImage) } func imageFromURLString(_ urlString: String?) -> UIImage? { - return nil + nil } func loadImageFromURLString(_ urlString: String) async -> Result { - return .failure(.failedRetrievingImage) + .failure(.failedRetrievingImage) } } diff --git a/ElementX/Sources/Services/Room/Messages/EmoteRoomMessage.swift b/ElementX/Sources/Services/Room/Messages/EmoteRoomMessage.swift index f81d00a7b..82c28b64c 100644 --- a/ElementX/Sources/Services/Room/Messages/EmoteRoomMessage.swift +++ b/ElementX/Sources/Services/Room/Messages/EmoteRoomMessage.swift @@ -7,8 +7,8 @@ // import Foundation -import UIKit import MatrixRustSDK +import UIKit struct EmoteRoomMessage: RoomMessageProtocol { private let message: MatrixRustSDK.EmoteMessage diff --git a/ElementX/Sources/Services/Room/Messages/ImageRoomMessage.swift b/ElementX/Sources/Services/Room/Messages/ImageRoomMessage.swift index f93e93105..d29b1b6f7 100644 --- a/ElementX/Sources/Services/Room/Messages/ImageRoomMessage.swift +++ b/ElementX/Sources/Services/Room/Messages/ImageRoomMessage.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import MatrixRustSDK +import UIKit struct ImageRoomMessage: RoomMessageProtocol { private let message: MatrixRustSDK.ImageMessage diff --git a/ElementX/Sources/Services/Room/Messages/NoticeRoomMessage.swift b/ElementX/Sources/Services/Room/Messages/NoticeRoomMessage.swift index 98027f5f0..f7e293e53 100644 --- a/ElementX/Sources/Services/Room/Messages/NoticeRoomMessage.swift +++ b/ElementX/Sources/Services/Room/Messages/NoticeRoomMessage.swift @@ -7,8 +7,8 @@ // import Foundation -import UIKit import MatrixRustSDK +import UIKit struct NoticeRoomMessage: RoomMessageProtocol { private let message: MatrixRustSDK.NoticeMessage diff --git a/ElementX/Sources/Services/Room/Messages/TextRoomMessage.swift b/ElementX/Sources/Services/Room/Messages/TextRoomMessage.swift index 22b9bd57b..772f7448d 100644 --- a/ElementX/Sources/Services/Room/Messages/TextRoomMessage.swift +++ b/ElementX/Sources/Services/Room/Messages/TextRoomMessage.swift @@ -7,8 +7,8 @@ // import Foundation -import UIKit import MatrixRustSDK +import UIKit struct TextRoomMessage: RoomMessageProtocol { private let message: MatrixRustSDK.TextMessage diff --git a/ElementX/Sources/Services/Room/MockRoomProxy.swift b/ElementX/Sources/Services/Room/MockRoomProxy.swift index aeb0f7333..baa224b1b 100644 --- a/ElementX/Sources/Services/Room/MockRoomProxy.swift +++ b/ElementX/Sources/Services/Room/MockRoomProxy.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import UIKit -import Combine struct MockRoomProxy: RoomProxyProtocol { let id = UUID().uuidString @@ -29,26 +29,24 @@ struct MockRoomProxy: RoomProxyProtocol { var callbacks = PassthroughSubject() func loadDisplayNameForUserId(_ userId: String) async -> Result { - return .failure(.failedRetrievingMemberDisplayName) + .failure(.failedRetrievingMemberDisplayName) } func loadAvatarURLForUserId(_ userId: String) async -> Result { - return .failure(.failedRetrievingMemberAvatarURL) + .failure(.failedRetrievingMemberAvatarURL) } func loadDisplayName() async -> Result { - return .failure(.failedRetrievingDisplayName) + .failure(.failedRetrievingDisplayName) } - func startLiveEventListener() { - - } + func startLiveEventListener() { } func paginateBackwards(count: UInt) async -> Result { - return .failure(.backwardStreamNotAvailable) + .failure(.backwardStreamNotAvailable) } func sendMessage(_ message: String) async -> Result { - return .failure(.failedSendingMessage) + .failure(.failedSendingMessage) } } diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index b9b1d1ae7..f70d7f94b 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import UIKit -import Combine import MatrixRustSDK diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index e1298f2c8..cdae297c4 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Combine +import UIKit enum RoomProxyError: Error { case failedRetrievingDisplayName diff --git a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummary.swift b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummary.swift index 8c6a67d60..bda92b478 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummary.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummary.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Combine +import UIKit struct MockRoomSummary: RoomSummaryProtocol { var id: String = UUID().uuidString @@ -18,21 +18,19 @@ struct MockRoomSummary: RoomSummaryProtocol { var topic: String? - var isDirect: Bool = false + var isDirect = false - var isEncrypted: Bool = false + var isEncrypted = false - var isSpace: Bool = false + var isSpace = false - var isTombstoned: Bool = false + var isTombstoned = false var lastMessage: EventBrief? var avatar: UIImage? - func loadDetails() async { - - } + func loadDetails() async { } var callbacks = PassthroughSubject() } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift index f23717807..50e91b78e 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import UIKit -import Combine class RoomSummary: RoomSummaryProtocol { private let roomProxy: RoomProxyProtocol diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProtocol.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProtocol.swift index cba73691c..8561effcc 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import Combine +import UIKit enum RoomSummaryCallback { case updatedData diff --git a/ElementX/Sources/Services/Session/UserSession.swift b/ElementX/Sources/Services/Session/UserSession.swift index 3c6577686..8cf709d43 100644 --- a/ElementX/Sources/Services/Session/UserSession.swift +++ b/ElementX/Sources/Services/Session/UserSession.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation class UserSession: UserSessionProtocol { private var cancellables = Set() diff --git a/ElementX/Sources/Services/Session/UserSessionProtocol.swift b/ElementX/Sources/Services/Session/UserSessionProtocol.swift index dd66ad4f6..3b39dd573 100644 --- a/ElementX/Sources/Services/Session/UserSessionProtocol.swift +++ b/ElementX/Sources/Services/Session/UserSessionProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation enum UserSessionCallback { case sessionVerificationNeeded diff --git a/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift b/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift index e28d42f96..59549a984 100644 --- a/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift +++ b/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift @@ -6,14 +6,14 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import MatrixRustSDK -import Combine struct MockSessionVerificationControllerProxy: SessionVerificationControllerProxyProtocol { var callbacks = PassthroughSubject() - var isVerified: Bool = false + var isVerified = false func requestVerification() async -> Result { DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 2.0) { @@ -50,13 +50,14 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx // MARK: - Private static var emojis: [SessionVerificationEmoji] { - [SessionVerificationEmoji(symbol: "🦋", description: "Butterfly"), - SessionVerificationEmoji(symbol: "🐘", description: "Elephant"), - SessionVerificationEmoji(symbol: "🦋", description: "Butterfly"), - SessionVerificationEmoji(symbol: "🎂", description: "Cake"), - SessionVerificationEmoji(symbol: "🎂", description: "Cake"), - SessionVerificationEmoji(symbol: "🏁", description: "Flag"), - SessionVerificationEmoji(symbol: "🌏", description: "Globe") + [ + SessionVerificationEmoji(symbol: "🦋", description: "Butterfly"), + SessionVerificationEmoji(symbol: "🐘", description: "Elephant"), + SessionVerificationEmoji(symbol: "🦋", description: "Butterfly"), + SessionVerificationEmoji(symbol: "🎂", description: "Cake"), + SessionVerificationEmoji(symbol: "🎂", description: "Cake"), + SessionVerificationEmoji(symbol: "🏁", description: "Flag"), + SessionVerificationEmoji(symbol: "🌏", description: "Globe") ] } } diff --git a/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxy.swift b/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxy.swift index 3157f7b6e..9a07c88ec 100644 --- a/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxy.swift +++ b/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxy.swift @@ -6,9 +6,9 @@ // Copyright © 2022 Element. All rights reserved. // +import Combine import Foundation import MatrixRustSDK -import Combine private class WeakSessionVerificationControllerProxy: SessionVerificationControllerDelegate { private weak var proxy: SessionVerificationControllerProxy? diff --git a/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxyProtocol.swift b/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxyProtocol.swift index c3f07459d..4f1eacf43 100644 --- a/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxyProtocol.swift +++ b/ElementX/Sources/Services/SessionVerification/SessionVerificationControllerProxyProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation enum SessionVerificationControllerProxyError: Error { case failedRequestingVerification diff --git a/ElementX/Sources/Services/Timeline/MockRoomTimelineController.swift b/ElementX/Sources/Services/Timeline/MockRoomTimelineController.swift index d1ff65908..0ef4f8d6f 100644 --- a/ElementX/Sources/Services/Timeline/MockRoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/MockRoomTimelineController.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation class MockRoomTimelineController: RoomTimelineControllerProtocol { @@ -40,18 +40,12 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol { senderDisplayName: "Bob")] func paginateBackwards(_ count: UInt) async -> Result { - return .failure(.generic) + .failure(.generic) } - func processItemAppearance(_ itemId: String) async { - - } + func processItemAppearance(_ itemId: String) async { } - func processItemDisappearance(_ itemId: String) async { - - } + func processItemDisappearance(_ itemId: String) async { } - func sendMessage(_ message: String) async { - - } + func sendMessage(_ message: String) async { } } diff --git a/ElementX/Sources/Services/Timeline/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/RoomTimelineController.swift index 5c3fe6f8b..a8dd9b4cc 100644 --- a/ElementX/Sources/Services/Timeline/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/RoomTimelineController.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation import UIKit class RoomTimelineController: RoomTimelineControllerProtocol { @@ -79,9 +79,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol { } } - func processItemDisappearance(_ itemId: String) { - - } + func processItemDisappearance(_ itemId: String) { } func sendMessage(_ message: String) async { switch await timelineProvider.sendMessage(message) { diff --git a/ElementX/Sources/Services/Timeline/RoomTimelineControllerProtocol.swift b/ElementX/Sources/Services/Timeline/RoomTimelineControllerProtocol.swift index 4db9e68b3..f3e93be46 100644 --- a/ElementX/Sources/Services/Timeline/RoomTimelineControllerProtocol.swift +++ b/ElementX/Sources/Services/Timeline/RoomTimelineControllerProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation enum RoomTimelineControllerCallback { case updatedTimelineItems diff --git a/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift b/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift index 757cb4636..cf379f8e5 100644 --- a/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift +++ b/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation class RoomTimelineProvider: RoomTimelineProviderProtocol { private let roomProxy: RoomProxyProtocol @@ -21,13 +21,13 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol { self.roomProxy.callbacks .receive(on: DispatchQueue.main) .sink { [weak self] callback in - guard let self = self else { return } + guard let self = self else { return } - switch callback { - case .updatedMessages: - self.callbacks.send(.updatedMessages) - } - }.store(in: &cancellables) + switch callback { + case .updatedMessages: + self.callbacks.send(.updatedMessages) + } + }.store(in: &cancellables) } var messages: [RoomMessageProtocol] { diff --git a/ElementX/Sources/Services/Timeline/RoomTimelineProviderProtocol.swift b/ElementX/Sources/Services/Timeline/RoomTimelineProviderProtocol.swift index 67b04ff63..1911a6dc2 100644 --- a/ElementX/Sources/Services/Timeline/RoomTimelineProviderProtocol.swift +++ b/ElementX/Sources/Services/Timeline/RoomTimelineProviderProtocol.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import Foundation import Combine +import Foundation enum RoomTimelineProviderCallback { case updatedMessages @@ -26,5 +26,5 @@ protocol RoomTimelineProviderProtocol { func paginateBackwards(_ count: UInt) async -> Result - func sendMessage(_ message: String) async -> Result + func sendMessage(_ message: String) async -> Result } diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/DecorationTimelineItemProtocol.swift b/ElementX/Sources/Services/Timeline/TimelineItems/DecorationTimelineItemProtocol.swift index ca291f50d..71714ea1b 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/DecorationTimelineItemProtocol.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/DecorationTimelineItemProtocol.swift @@ -8,6 +8,4 @@ import Foundation -protocol DecorationTimelineItemProtocol: RoomTimelineItemProtocol { - -} +protocol DecorationTimelineItemProtocol: RoomTimelineItemProtocol { } diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift index 9116db0b7..1af8d5668 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift @@ -42,6 +42,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { } // MARK: - Private + private func buildTextTimelineItemFromMessage(_ message: TextRoomMessage, _ isOutgoing: Bool, _ showSenderDetails: Bool, diff --git a/ElementX/Sources/Services/UserSessionStore/UserSessionStore.swift b/ElementX/Sources/Services/UserSessionStore/UserSessionStore.swift index b3f1f3e1f..ab1357b50 100644 --- a/ElementX/Sources/Services/UserSessionStore/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSessionStore/UserSessionStore.swift @@ -15,8 +15,8 @@ // import Foundation -import MatrixRustSDK import Kingfisher +import MatrixRustSDK class UserSessionStore: UserSessionStoreProtocol { diff --git a/ElementX/Sources/UITestScreenIdentifier.swift b/ElementX/Sources/UITestScreenIdentifier.swift index e00e0e0be..5a683de3e 100644 --- a/ElementX/Sources/UITestScreenIdentifier.swift +++ b/ElementX/Sources/UITestScreenIdentifier.swift @@ -26,7 +26,7 @@ enum UITestScreenIdentifier: String { extension UITestScreenIdentifier: CustomStringConvertible { var description: String { - return rawValue.titlecased() + rawValue.titlecased() } } @@ -38,7 +38,7 @@ private extension String { with: " $1", options: .regularExpression, range: range(of: self)) - .trimmingCharacters(in: .whitespacesAndNewlines) - .capitalized + .trimmingCharacters(in: .whitespacesAndNewlines) + .capitalized } } diff --git a/ElementX/Sources/UITestsAppCoordinator.swift b/ElementX/Sources/UITestsAppCoordinator.swift index 6892eb759..551c327c1 100644 --- a/ElementX/Sources/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITestsAppCoordinator.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import UIKit import SwiftUI +import UIKit class UITestsAppCoordinator: Coordinator { private let window: UIWindow diff --git a/ElementX/SupportingFiles/target.yml b/ElementX/SupportingFiles/target.yml index 7bac9c265..a1083a1f0 100644 --- a/ElementX/SupportingFiles/target.yml +++ b/ElementX/SupportingFiles/target.yml @@ -58,6 +58,16 @@ targets: SWIFT_OBJC_BRIDGING_HEADER: ElementX/SupportingFiles/ElementX-Bridging-Header.h preBuildScripts: + - name: 🧹 SwiftFormat + runOnlyWhenInstalling: false + shell: /bin/sh + script: | + export PATH="$PATH:/opt/homebrew/bin" + if which swiftformat >/dev/null; then + swiftformat $PROJECT_DIR + else + echo "warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat" + fi - name: 🛠 SwiftGen runOnlyWhenInstalling: false shell: /bin/sh diff --git a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateModels.swift b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateModels.swift index 24edd12f7..a07d0888d 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateModels.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateModels.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateViewModelProtocol.swift b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateViewModelProtocol.swift index a46e807af..3cb2493fb 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateViewModelProtocol.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateViewModelProtocol.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/View/TemplateScreen.swift b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/View/TemplateScreen.swift index c4ca9eee6..3b8a49a62 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/View/TemplateScreen.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/View/TemplateScreen.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/Tools/Scripts/Templates/SimpleScreenExample/Tests/UI/TemplateScreenUITests.swift b/Tools/Scripts/Templates/SimpleScreenExample/Tests/UI/TemplateScreenUITests.swift index 1a3e0e0b3..c5a1d5e9e 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/Tests/UI/TemplateScreenUITests.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/Tests/UI/TemplateScreenUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest class TemplateScreenUITests: XCTestCase { func testRegularScreen() { diff --git a/Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit/TemplateViewModelTests.swift b/Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit/TemplateViewModelTests.swift index 474bc585d..405500ab1 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit/TemplateViewModelTests.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit/TemplateViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UITests/Sources/Application.swift b/UITests/Sources/Application.swift index 056467184..520b9bc48 100644 --- a/UITests/Sources/Application.swift +++ b/UITests/Sources/Application.swift @@ -19,11 +19,11 @@ struct Application { extension XCUIApplication { func goToScreenWithIdentifier(_ identifier: UITestScreenIdentifier) { - let button = self.buttons[identifier.rawValue] + let button = buttons[identifier.rawValue] let lastLabel = staticTexts["lastItem"] - while !button.isHittable && !lastLabel.isHittable { - self.tables.firstMatch.swipeUp() + while !button.isHittable, !lastLabel.isHittable { + tables.firstMatch.swipeUp() } button.tap() diff --git a/UITests/Sources/BugReportUITests.swift b/UITests/Sources/BugReportUITests.swift index 9523605e2..81b90187c 100644 --- a/UITests/Sources/BugReportUITests.swift +++ b/UITests/Sources/BugReportUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest class BugReportUITests: XCTestCase { diff --git a/UITests/Sources/LoginScreenUITests.swift b/UITests/Sources/LoginScreenUITests.swift index 0a6a1f777..b03edf133 100644 --- a/UITests/Sources/LoginScreenUITests.swift +++ b/UITests/Sources/LoginScreenUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest @MainActor class LoginScreenUITests: XCTestCase { diff --git a/UITests/Sources/RoomScreenUITests.swift b/UITests/Sources/RoomScreenUITests.swift index faa75961e..7abc3941b 100644 --- a/UITests/Sources/RoomScreenUITests.swift +++ b/UITests/Sources/RoomScreenUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest @MainActor class RoomScreenUITests: XCTestCase { diff --git a/UITests/Sources/ServerSelectionUITests.swift b/UITests/Sources/ServerSelectionUITests.swift index 148454254..29b47e134 100644 --- a/UITests/Sources/ServerSelectionUITests.swift +++ b/UITests/Sources/ServerSelectionUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest @MainActor class ServerSelectionUITests: XCTestCase { diff --git a/UITests/Sources/SessionVerificationUITests.swift b/UITests/Sources/SessionVerificationUITests.swift index 280b3eabb..0fae9332e 100644 --- a/UITests/Sources/SessionVerificationUITests.swift +++ b/UITests/Sources/SessionVerificationUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest class SessionVerificationUITests: XCTestCase { diff --git a/UITests/Sources/SettingsUITests.swift b/UITests/Sources/SettingsUITests.swift index e7d9134c3..8dd82c594 100644 --- a/UITests/Sources/SettingsUITests.swift +++ b/UITests/Sources/SettingsUITests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import ElementX +import XCTest class SettingsUITests: XCTestCase { diff --git a/UnitTests/Sources/AttributedStringBuilderTests.swift b/UnitTests/Sources/AttributedStringBuilderTests.swift index 300626728..b11274616 100644 --- a/UnitTests/Sources/AttributedStringBuilderTests.swift +++ b/UnitTests/Sources/AttributedStringBuilderTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import XCTest @testable import ElementX +import XCTest class AttributedStringBuilderTests: XCTestCase { @@ -15,16 +15,16 @@ class AttributedStringBuilderTests: XCTestCase { let maxHeaderPointSize = ceil(UIFont.preferredFont(forTextStyle: .body).pointSize * 1.2) func testRenderHTMLStringWithHeaders() { - let h1HTMLString = "

Large Heading

"; - let h2HTMLString = "

Smaller Heading

"; - let h3HTMLString = "

Acceptable Heading

"; + let h1HTMLString = "

Large Heading

" + let h2HTMLString = "

Smaller Heading

" + let h3HTMLString = "

Acceptable Heading

" guard let h1AttributedString = attributedStringBuilder.fromHTML(h1HTMLString), let h2AttributedString = attributedStringBuilder.fromHTML(h2HTMLString), let h3AttributedString = attributedStringBuilder.fromHTML(h3HTMLString) else { - XCTFail("Could not build the attributed string") - return - } + XCTFail("Could not build the attributed string") + return + } XCTAssertEqual(String(h1AttributedString.characters), "Large Heading") XCTAssertEqual(String(h2AttributedString.characters), "Smaller Heading") @@ -34,16 +34,19 @@ class AttributedStringBuilderTests: XCTestCase { XCTAssert(h2AttributedString.runs.count == 1) XCTAssert(h3AttributedString.runs.count == 1) - let h1Font = h1AttributedString.runs.first?.uiKit.font - let h2Font = h2AttributedString.runs.first?.uiKit.font - let h3Font = h3AttributedString.runs.first?.uiKit.font + guard let h1Font = h1AttributedString.runs.first?.uiKit.font, + let h2Font = h2AttributedString.runs.first?.uiKit.font, + let h3Font = h3AttributedString.runs.first?.uiKit.font else { + XCTFail("Could not extract a font from the strings.") + return + } XCTAssertEqual(h1Font, h2Font) XCTAssertEqual(h2Font, h3Font) - XCTAssert(h1Font!.pointSize > UIFont.preferredFont(forTextStyle: .body).pointSize) + XCTAssert(h1Font.pointSize > UIFont.preferredFont(forTextStyle: .body).pointSize) - XCTAssert(h1Font!.pointSize <= maxHeaderPointSize) + XCTAssert(h1Font.pointSize <= maxHeaderPointSize) } func testRenderHTMLStringWithPreCode() { @@ -57,19 +60,24 @@ class AttributedStringBuilderTests: XCTestCase { XCTAssertEqual(attributedString.runs.first?.uiKit.font?.fontName, "Menlo-Regular") let string = String(attributedString.characters) - let regex = try! NSRegularExpression(pattern: "\\R", options: []) + + guard let regex = try? NSRegularExpression(pattern: "\\R", options: []) else { + XCTFail("Could not build the regex for the test.") + return + } + XCTAssertEqual(regex.numberOfMatches(in: string, options: [], range: .init(location: 0, length: string.count)), 3) } func testRenderHTMLStringWithLink() { - let htmlString = "This text contains a link."; + let htmlString = "This text contains a link." guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { XCTFail("Could not build the attributed string") return } - XCTAssertEqual(String(attributedString.characters), "This text contains a link."); + XCTAssertEqual(String(attributedString.characters), "This text contains a link.") XCTAssertEqual(attributedString.runs.count, 3) @@ -79,14 +87,14 @@ class AttributedStringBuilderTests: XCTestCase { } func testRenderPlainStringWithLink() { - let plainString = "This text contains a https://www.matrix.org link."; + let plainString = "This text contains a https://www.matrix.org link." guard let attributedString = attributedStringBuilder.fromPlain(plainString) else { XCTFail("Could not build the attributed string") return } - XCTAssertEqual(String(attributedString.characters), plainString); + XCTAssertEqual(String(attributedString.characters), plainString) XCTAssertEqual(attributedString.runs.count, 3) @@ -96,16 +104,16 @@ class AttributedStringBuilderTests: XCTestCase { } func testRenderHTMLStringWithLinkInHeader() { - let h1HTMLString = "

Matrix.org

"; - let h2HTMLString = "

Matrix.org

"; - let h3HTMLString = "

Matrix.org

"; + let h1HTMLString = "

Matrix.org

" + let h2HTMLString = "

Matrix.org

" + let h3HTMLString = "

Matrix.org

" guard let h1AttributedString = attributedStringBuilder.fromHTML(h1HTMLString), let h2AttributedString = attributedStringBuilder.fromHTML(h2HTMLString), let h3AttributedString = attributedStringBuilder.fromHTML(h3HTMLString) else { - XCTFail("Could not build the attributed string") - return - } + XCTFail("Could not build the attributed string") + return + } XCTAssertEqual(String(h1AttributedString.characters), "Matrix.org") XCTAssertEqual(String(h2AttributedString.characters), "Matrix.org") @@ -115,15 +123,18 @@ class AttributedStringBuilderTests: XCTestCase { XCTAssertEqual(h2AttributedString.runs.count, 1) XCTAssertEqual(h3AttributedString.runs.count, 1) - let h1Font = h1AttributedString.runs.first?.uiKit.font - let h2Font = h2AttributedString.runs.first?.uiKit.font - let h3Font = h3AttributedString.runs.first?.uiKit.font - + guard let h1Font = h1AttributedString.runs.first?.uiKit.font, + let h2Font = h2AttributedString.runs.first?.uiKit.font, + let h3Font = h3AttributedString.runs.first?.uiKit.font else { + XCTFail("Could not extract a font from the strings.") + return + } + XCTAssertEqual(h1Font, h2Font) XCTAssertEqual(h2Font, h3Font) - XCTAssert(h1Font!.pointSize > UIFont.preferredFont(forTextStyle: .body).pointSize) - XCTAssert(h1Font!.pointSize <= maxHeaderPointSize) + XCTAssert(h1Font.pointSize > UIFont.preferredFont(forTextStyle: .body).pointSize) + XCTAssert(h1Font.pointSize <= maxHeaderPointSize) XCTAssertEqual(h1AttributedString.runs.first?.link?.host, "www.matrix.org") XCTAssertEqual(h2AttributedString.runs.first?.link?.host, "www.matrix.org") @@ -131,7 +142,7 @@ class AttributedStringBuilderTests: XCTestCase { } func testRenderHTMLStringWithIFrame() { - let htmlString = ""; + let htmlString = "" guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { XCTFail("Could not build the attributed string") @@ -143,28 +154,28 @@ class AttributedStringBuilderTests: XCTestCase { func testUserIdLink() { let userId = "@user:matrix.org" - let string = "The user is \(userId)."; + let string = "The user is \(userId)." checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expected: userId) checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expected: userId) } func testRoomAliasLink() { let roomAlias = "#matrix:matrix.org" - let string = "The room alias is \(roomAlias)."; + let string = "The room alias is \(roomAlias)." checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expected: roomAlias) checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expected: roomAlias) } func testRoomIdLink() { let roomId = "!roomidentifier:matrix.org" - let string = "The room is \(roomId)."; + let string = "The room is \(roomId)." checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expected: roomId) checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expected: roomId) } func testEventIdLink() { let eventId = "$eventidentifier:matrix.org" - let string = "The event is \(eventId)."; + let string = "The event is \(eventId)." checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expected: eventId) checkMatrixEntityLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expected: eventId) } @@ -200,6 +211,7 @@ class AttributedStringBuilderTests: XCTestCase { } func testCustomForegroundColor() { + // swiftlint:disable:next line_length let htmlString = "Rain www.matrix.org bow" guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { @@ -244,12 +256,13 @@ class AttributedStringBuilderTests: XCTestCase { XCTFail("Couldn't find blockquote") } + // swiftlint:disable line_length func testBlockquoteWithinText() { let htmlString = """ -The text before the blockquote -
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
-The text after the blockquote -""" + The text before the blockquote +
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
+ The text after the blockquote + """ guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { XCTFail("Could not build the attributed string") @@ -268,6 +281,8 @@ The text after the blockquote XCTFail("Couldn't find blockquote") } + + // swiftlint:enable line_length func testBlockquoteWithLink() { let htmlString = "
Blockquote with a link in it
" @@ -289,7 +304,7 @@ The text after the blockquote var foundBlockquoteAndLink = false for run in attributedString.runs { - if run.elementX.blockquote != nil && run.link != nil { + if run.elementX.blockquote != nil, run.link != nil { foundBlockquoteAndLink = true } } @@ -299,10 +314,10 @@ The text after the blockquote func testMultipleGroupedBlockquotes() { let htmlString = """ -
First blockquote with a link in it
-
Second blockquote with a link in it
-
Third blockquote with a link in it
-""" +
First blockquote with a link in it
+
Second blockquote with a link in it
+
Third blockquote with a link in it
+ """ guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { XCTFail("Could not build the attributed string") @@ -315,7 +330,7 @@ The text after the blockquote var numberOfBlockquotes = 0 for run in attributedString.runs { - if run.elementX.blockquote != nil && run.link != nil { + if run.elementX.blockquote != nil, run.link != nil { numberOfBlockquotes += 1 } } @@ -325,13 +340,13 @@ The text after the blockquote func testMultipleSeparatedBlockquotes() { let htmlString = """ -First -
blockquote with a link in it
-Second -
blockquote with a link in it
-Third -
blockquote with a link in it
-""" + First +
blockquote with a link in it
+ Second +
blockquote with a link in it
+ Third +
blockquote with a link in it
+ """ guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else { XCTFail("Could not build the attributed string") @@ -344,7 +359,7 @@ Third var numberOfBlockquotes = 0 for run in attributedString.runs { - if run.elementX.blockquote != nil && run.link != nil { + if run.elementX.blockquote != nil, run.link != nil { numberOfBlockquotes += 1 } } diff --git a/UnitTests/Sources/BackgroundTaskTests.swift b/UnitTests/Sources/BackgroundTaskTests.swift index 58b02fe4e..c67319a0b 100644 --- a/UnitTests/Sources/BackgroundTaskTests.swift +++ b/UnitTests/Sources/BackgroundTaskTests.swift @@ -13,7 +13,7 @@ import XCTest class BackgroundTaskTests: XCTestCase { private enum Constants { - static let bgTaskName: String = "test" + static let bgTaskName = "test" } func testInAnExtension() { @@ -192,7 +192,7 @@ private class MockApplication: ApplicationProtocol { self.allowTasks = allowTasks } - private static var bgTaskIdentifier: Int = 0 + private static var bgTaskIdentifier = 0 private var bgTasks: [UIBackgroundTaskIdentifier: Bool] = [:] diff --git a/UnitTests/Sources/BugReportServiceTests.swift b/UnitTests/Sources/BugReportServiceTests.swift index 4476f0028..7e6be6c22 100644 --- a/UnitTests/Sources/BugReportServiceTests.swift +++ b/UnitTests/Sources/BugReportServiceTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 element.io. All rights reserved. // -import Foundation @testable import ElementX +import Foundation import XCTest class BugReportServiceTests: XCTestCase { @@ -69,11 +69,11 @@ private class MockURLProtocol: URLProtocol { } override class func canonicalRequest(for request: URLRequest) -> URLRequest { - return request + request } override class func canInit(with request: URLRequest) -> Bool { - return true + true } } diff --git a/UnitTests/Sources/BugReportViewModelTests.swift b/UnitTests/Sources/BugReportViewModelTests.swift index 73b517157..e01dbaf29 100644 --- a/UnitTests/Sources/BugReportViewModelTests.swift +++ b/UnitTests/Sources/BugReportViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/ElementXTests.swift b/UnitTests/Sources/ElementXTests.swift index bab4dc16b..bf5c79e42 100644 --- a/UnitTests/Sources/ElementXTests.swift +++ b/UnitTests/Sources/ElementXTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import XCTest @testable import ElementX +import XCTest class ElementXTests: XCTestCase { diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index 93b5292b0..642762367 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/ImageAnonymizerTests.swift b/UnitTests/Sources/ImageAnonymizerTests.swift index c66c1669e..5a5087b6e 100644 --- a/UnitTests/Sources/ImageAnonymizerTests.swift +++ b/UnitTests/Sources/ImageAnonymizerTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 element.io. All rights reserved. // -import XCTest @testable import ElementX +import XCTest enum ImageAnonymizerTestsError: String, Error { case screenshotNotFound @@ -24,7 +24,7 @@ class ImageAnonymizerTests: XCTestCase { } func sampleScreenshot() throws -> UIImage { - let bundle = Bundle(for: self.classForCoder) + let bundle = Bundle(for: classForCoder) guard let path = bundle.path(forResource: "sample_screenshot", ofType: "png"), let image = UIImage(contentsOfFile: path) else { throw ImageAnonymizerTestsError.screenshotNotFound diff --git a/UnitTests/Sources/KeychainControllerTests.swift b/UnitTests/Sources/KeychainControllerTests.swift index 5912dc050..ac7d254df 100644 --- a/UnitTests/Sources/KeychainControllerTests.swift +++ b/UnitTests/Sources/KeychainControllerTests.swift @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest @testable import ElementX +import XCTest class KeychainControllerTests: XCTestCase { var keychain: KeychainController! diff --git a/UnitTests/Sources/LocalizationTests.swift b/UnitTests/Sources/LocalizationTests.swift index b79c056a2..73ac5c819 100644 --- a/UnitTests/Sources/LocalizationTests.swift +++ b/UnitTests/Sources/LocalizationTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Element. All rights reserved. // -import XCTest @testable import ElementX +import XCTest class LocalizationTests: XCTestCase { @@ -70,9 +70,9 @@ class LocalizationTests: XCTestCase { // set app language to Polish Bundle.elementLanguage = "pl" - XCTAssertEqual(ElementL10n.seconds(1), "1 sekunda") // one - XCTAssertEqual(ElementL10n.seconds(2), "2 sekundy") // few - XCTAssertEqual(ElementL10n.seconds(5), "5 sekund") // many, other + XCTAssertEqual(ElementL10n.seconds(1), "1 sekunda") // one + XCTAssertEqual(ElementL10n.seconds(2), "2 sekundy") // few + XCTAssertEqual(ElementL10n.seconds(5), "5 sekund") // many, other } /// Test plurals fallback language for a language not supported at all diff --git a/UnitTests/Sources/LoggingTests.swift b/UnitTests/Sources/LoggingTests.swift index 4d12ca3df..eaa193256 100644 --- a/UnitTests/Sources/LoggingTests.swift +++ b/UnitTests/Sources/LoggingTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 element.io. All rights reserved. // -import XCTest @testable import ElementX +import XCTest class LoggingTests: XCTestCase { diff --git a/UnitTests/Sources/LoginViewModelTests.swift b/UnitTests/Sources/LoginViewModelTests.swift index 24ae86a49..501729b6a 100644 --- a/UnitTests/Sources/LoginViewModelTests.swift +++ b/UnitTests/Sources/LoginViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/RoomScreenViewModelTests.swift b/UnitTests/Sources/RoomScreenViewModelTests.swift index d1481d731..66a80b649 100644 --- a/UnitTests/Sources/RoomScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomScreenViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,4 @@ import XCTest -class RoomScreenViewModelTests: XCTestCase { - -} +class RoomScreenViewModelTests: XCTestCase { } diff --git a/UnitTests/Sources/ScreenshotDetectorTests.swift b/UnitTests/Sources/ScreenshotDetectorTests.swift index 2f94c4736..bd70fd5e3 100644 --- a/UnitTests/Sources/ScreenshotDetectorTests.swift +++ b/UnitTests/Sources/ScreenshotDetectorTests.swift @@ -6,10 +6,10 @@ // Copyright © 2022 element.io. All rights reserved. // -import Foundation @testable import ElementX -import XCTest +import Foundation import Photos +import XCTest class ScreenshotDetectorTests: XCTestCase { diff --git a/UnitTests/Sources/ServerSelectionViewModelTests.swift b/UnitTests/Sources/ServerSelectionViewModelTests.swift index 597a6915f..8823bb690 100644 --- a/UnitTests/Sources/ServerSelectionViewModelTests.swift +++ b/UnitTests/Sources/ServerSelectionViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/SessionVerificationViewModelTests.swift b/UnitTests/Sources/SessionVerificationViewModelTests.swift index 339a74a46..b5ccd9f7f 100644 --- a/UnitTests/Sources/SessionVerificationViewModelTests.swift +++ b/UnitTests/Sources/SessionVerificationViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,8 @@ // limitations under the License. // -import XCTest import Combine +import XCTest @testable import ElementX diff --git a/UnitTests/Sources/SettingsViewModelTests.swift b/UnitTests/Sources/SettingsViewModelTests.swift index d867988c8..cf5aaa2e9 100644 --- a/UnitTests/Sources/SettingsViewModelTests.swift +++ b/UnitTests/Sources/SettingsViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/SplashScreenViewModelTests.swift b/UnitTests/Sources/SplashScreenViewModelTests.swift index 858caad50..0e2e1b119 100644 --- a/UnitTests/Sources/SplashScreenViewModelTests.swift +++ b/UnitTests/Sources/SplashScreenViewModelTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/UnitTests/Sources/UserIndicators/UserIndicatorPresenterSpy.swift b/UnitTests/Sources/UserIndicators/UserIndicatorPresenterSpy.swift index c140613df..95306a7bd 100644 --- a/UnitTests/Sources/UserIndicators/UserIndicatorPresenterSpy.swift +++ b/UnitTests/Sources/UserIndicators/UserIndicatorPresenterSpy.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +14,8 @@ // limitations under the License. // -import Foundation @testable import ElementX +import Foundation class UserIndicatorPresenterSpy: UserIndicatorViewPresentable { var intel = [String]() diff --git a/UnitTests/Sources/UserIndicators/UserIndicatorQueueTests.swift b/UnitTests/Sources/UserIndicators/UserIndicatorQueueTests.swift index c8a2835fe..067d358df 100644 --- a/UnitTests/Sources/UserIndicators/UserIndicatorQueueTests.swift +++ b/UnitTests/Sources/UserIndicators/UserIndicatorQueueTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,9 @@ // limitations under the License. // +@testable import ElementX import Foundation import XCTest -@testable import ElementX class UserIndicatorQueueTests: XCTestCase { var indicators: [UserIndicator]! @@ -28,7 +28,7 @@ class UserIndicatorQueueTests: XCTestCase { } func makeRequest() -> UserIndicatorRequest { - return UserIndicatorRequest( + UserIndicatorRequest( presenter: UserIndicatorPresenterSpy(), dismissal: .manual ) diff --git a/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift b/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift index 79db5cb99..1717b65dd 100644 --- a/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift +++ b/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift @@ -1,4 +1,4 @@ -// +// // Copyright 2021 New Vector Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,9 @@ // limitations under the License. // +@testable import ElementX import Foundation import XCTest -@testable import ElementX class UserIndicatorTests: XCTestCase { var presenter: UserIndicatorPresenterSpy! @@ -26,7 +26,7 @@ class UserIndicatorTests: XCTestCase { presenter = UserIndicatorPresenterSpy() } - func makeIndicator(dismissal: UserIndicatorDismissal = .manual, callback: @escaping () -> Void = {}) -> UserIndicator { + func makeIndicator(dismissal: UserIndicatorDismissal = .manual, callback: @escaping () -> Void = { }) -> UserIndicator { let request = UserIndicatorRequest( presenter: presenter, dismissal: dismissal diff --git a/changelog.d/pr-129.build b/changelog.d/pr-129.build new file mode 100644 index 000000000..8fa30e660 --- /dev/null +++ b/changelog.d/pr-129.build @@ -0,0 +1 @@ +Add swiftformat to the project and run it for the first time.