diff --git a/.swiftlint.yml b/.swiftlint.yml index 20e94fa76aa3..b2819760bd63 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -55,6 +55,9 @@ only_rules: - shorthand_optional_binding + # Prefer `someBool.toggle()` over `someBool = !someBool`. + - toggle_bool + # Files should have a single trailing newline. - trailing_newline diff --git a/Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/ReusableViews/TextFieldTableViewCell.swift b/Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/ReusableViews/TextFieldTableViewCell.swift index 21bb06190584..509631504805 100644 --- a/Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/ReusableViews/TextFieldTableViewCell.swift +++ b/Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/ReusableViews/TextFieldTableViewCell.swift @@ -173,7 +173,7 @@ private extension TextFieldTableViewCell { } @objc func secureTextEntryToggleAction(_ sender: Any) { - textField.isSecureTextEntry = !textField.isSecureTextEntry + textField.isSecureTextEntry.toggle() // Save and re-apply the current selection range to save the cursor position let currentTextRange = textField.selectedTextRange diff --git a/WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift b/WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift index 246067ad18b7..25a0f8315ea1 100644 --- a/WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift @@ -406,7 +406,7 @@ class SharingButtonsViewController: UITableViewController { switchCell.onChange = { [weak self] newValue in guard let self else { return } WPAnalytics.track(.sharingButtonsEditSharingButtonsToggled, properties: ["checked": newValue as Any], blog: self.blog) - self.buttonsSection.editing = !self.buttonsSection.editing + self.buttonsSection.editing.toggle() self.updateButtonOrderAfterEditing() self.reloadButtons() } @@ -452,7 +452,7 @@ class SharingButtonsViewController: UITableViewController { guard let self else { return } WPAnalytics.track(.sharingButtonsEditMoreButtonToggled, properties: ["checked": newValue as Any], blog: self.blog) self.updateButtonOrderAfterEditing() - self.moreSection.editing = !self.moreSection.editing + self.moreSection.editing.toggle() self.reloadButtons() } } diff --git a/WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift b/WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift index 0e7b06141a84..202eb654ed84 100644 --- a/WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift +++ b/WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift @@ -53,7 +53,7 @@ class ExpandableCell: WPReusableTableViewCell, NibLoadable { } public func toggle() { - expanded = !expanded + expanded.toggle() } private func setupSubviews() { diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift index 7cd623a0bfb4..3f73986e49b5 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift @@ -582,10 +582,10 @@ extension NotificationSettingsViewController { let section = self.section(at: index.section) switch section { case .blog: - displayBlogMoreWasAccepted = !displayBlogMoreWasAccepted + displayBlogMoreWasAccepted.toggle() case .followedSites: - displayFollowedMoreWasAccepted = !displayFollowedMoreWasAccepted + displayFollowedMoreWasAccepted.toggle() default: return diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift index 09d7dd8afeb9..381e27b21eba 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift @@ -96,7 +96,7 @@ class NoteBlockUserTableViewCell: NoteBlockTableViewCell { if let listener = isFollowOn ? onUnfollowClick : onFollowClick { listener() } - isFollowOn = !isFollowOn + isFollowOn.toggle() } } diff --git a/WordPress/Classes/ViewRelated/Plugins/ViewModels/PluginViewModel.swift b/WordPress/Classes/ViewRelated/Plugins/ViewModels/PluginViewModel.swift index 1e3dfc21cc3b..cc3d1addc8c7 100644 --- a/WordPress/Classes/ViewRelated/Plugins/ViewModels/PluginViewModel.swift +++ b/WordPress/Classes/ViewRelated/Plugins/ViewModels/PluginViewModel.swift @@ -383,7 +383,7 @@ class PluginViewModel: Observable { expandedText: setHTMLTextAttributes(text), expanded: descriptionExpandedStatus, action: { [unowned self] row in - self.descriptionExpandedStatus = !self.descriptionExpandedStatus + self.descriptionExpandedStatus.toggle() (row as? ExpandableRow)?.expanded = self.descriptionExpandedStatus }, onLinkTap: { [unowned self] url in @@ -399,7 +399,7 @@ class PluginViewModel: Observable { expandedText: setHTMLTextAttributes(text), expanded: installationExpandedStatus, action: { [unowned self] row in - self.installationExpandedStatus = !self.installationExpandedStatus + self.installationExpandedStatus.toggle() (row as? ExpandableRow)?.expanded = self.installationExpandedStatus }, onLinkTap: { [unowned self] url in @@ -415,7 +415,7 @@ class PluginViewModel: Observable { expandedText: setHTMLTextAttributes(text), expanded: changeLogExpandedStatus, action: { [unowned self] row in - self.changeLogExpandedStatus = !self.changeLogExpandedStatus + self.changeLogExpandedStatus.toggle() (row as? ExpandableRow)?.expanded = self.changeLogExpandedStatus }, onLinkTap: { [unowned self] url in @@ -431,7 +431,7 @@ class PluginViewModel: Observable { expandedText: setHTMLTextAttributes(text), expanded: faqExpandedStatus, action: { [unowned self] row in - self.faqExpandedStatus = !self.faqExpandedStatus + self.faqExpandedStatus.toggle() (row as? ExpandableRow)?.expanded = self.faqExpandedStatus }, onLinkTap: { [unowned self] url in diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/Tags View/ReaderTopicCollectionViewCoordinator.swift b/WordPress/Classes/ViewRelated/Reader/Cards/Tags View/ReaderTopicCollectionViewCoordinator.swift index e2f8db9358e0..6c58a0bd6edd 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/Tags View/ReaderTopicCollectionViewCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/Tags View/ReaderTopicCollectionViewCoordinator.swift @@ -206,7 +206,7 @@ extension ReaderTopicCollectionViewCoordinator: UICollectionViewDelegateFlowLayo return } - layout.isExpanded = !layout.isExpanded + layout.isExpanded.toggle() layout.invalidateLayout() WPAnalytics.trackReader(.readerChipsMoreToggled)