Fix various SwiftLint warnings.

This commit is contained in:
Brent Simmons committed 2026-01-02 10:30:01 -08:00
1 parent 36956c0345
commit f94d0c8d40
7 files changed
+180 -63

No files matched your search

@@ -1,11 +1,3 @@
//
// ModernTimelineCustomizerTableViewController.swift
// NetNewsWire-iOS
//
// Created by Stuart Breckenridge on 21/08/2025.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
import UIKit
import Articles
@@ -128,4 +120,4 @@ final class ModernTimelineCustomizerTableViewController: UITableViewController {
func userDefaultsDidChange() {
tableView.reloadSections(IndexSet(integersIn: 2...3), with: .none)
}
}
}
+4 -8
View File
@@ -167,8 +167,7 @@ final class DeleteCommand: UndoableCommand {
func restore() {
if let _ = feed {
restoreFeed()
}
else if let _ = folder {
} else if let _ = folder {
restoreFolder()
}
}
@@ -234,8 +233,7 @@ final class DeleteCommand: UndoableCommand {
while nomad != nil {
if let folder = nomad!.representedObject as? Folder {
folders += [folder]
}
else {
} else {
break
}
nomad = nomad!.parent
@@ -261,11 +259,9 @@ private struct DeleteActionName {
for node in nodes {
if let _ = node.representedObject as? Feed {
numberOfFeeds += 1
}
else if let _ = node.representedObject as? Folder {
} else if let _ = node.representedObject as? Folder {
numberOfFolders += 1
}
else {
} else {
return nil // Delete only Feeds and Folders.
}
}
@@ -40,8 +40,10 @@ extension NSAttributedString {
let baseDescriptor = baseFont.fontDescriptor
let baseSymbolicTraits = baseDescriptor.symbolicTraits
mutable.enumerateAttribute(.font, in: fullRange, options: []) { (font: Any?, range: NSRange, stop: UnsafeMutablePointer<ObjCBool>) in
guard let font = font as? Font else { return }
mutable.enumerateAttribute(.font, in: fullRange, options: []) { (font, range, _) in
guard let font = font as? Font else {
return
}
let currentDescriptor = font.fontDescriptor
let symbolicTraits = baseSymbolicTraits.union(currentDescriptor.symbolicTraits)
@@ -79,22 +81,22 @@ extension NSAttributedString {
init?(forTag: String) {
switch forTag {
case "b", "strong":
self = .bold
case "i", "em", "cite", "var", "dfn":
self = .italic
case "sup":
self = .superscript
case "sub":
self = .subscript
case "u", "ins":
self = .underline
case "s", "del":
self = .strikethrough
case "code", "samp", "tt", "kbd":
self = .monospace
default:
return nil
case "b", "strong":
self = .bold
case "i", "em", "cite", "var", "dfn":
self = .italic
case "sup":
self = .superscript
case "sub":
self = .subscript
case "u", "ins":
self = .underline
case "s", "del":
self = .strikethrough
case "code", "samp", "tt", "kbd":
self = .monospace
default:
return nil
}
}
}
@@ -170,7 +172,7 @@ extension NSAttributedString {
while let entitychar = iterator.next() {
if entitychar.isWhitespace {
lastchar = entitychar
break;
break
}
entity.append(entitychar)
@@ -276,13 +278,11 @@ private struct CountedSet<Element> where Element: Hashable {
}
func contains(_ element: Element) -> Bool {
return _storage[element] != nil
_storage[element] != nil
}
subscript(key: Element) -> Int {
get {
return _storage[key, default: 0]
}
_storage[key, default: 0]
}
}
+8 -10
View File
@@ -18,20 +18,20 @@ import Foundation
@MainActor struct ArticleSorter {
static func sortedByDate<T: SortableArticle>(articles: [T],
sortDirection: ComparisonResult,
groupByFeed: Bool) -> [T] {
static func sortedByDate<T: SortableArticle>(articles: [T], sortDirection: ComparisonResult, groupByFeed: Bool) -> [T] {
if groupByFeed {
return sortedByFeedName(articles: articles, sortByDateDirection: sortDirection)
} else {
return sortedByDate(articles: articles, sortDirection: sortDirection)
}
}
}
// MARK: -
// MARK: - Private
private static func sortedByFeedName<T: SortableArticle>(articles: [T],
sortByDateDirection: ComparisonResult) -> [T] {
private extension ArticleSorter {
static func sortedByFeedName<T: SortableArticle>(articles: [T], sortByDateDirection: ComparisonResult) -> [T] {
// Group articles by "feed-feedID" - feed ID is used to differentiate between
// two feeds that have the same name
let groupedArticles = Dictionary(grouping: articles) { "\($0.sortableName.lowercased())-\($0.sortableFeedID)" }
@@ -44,9 +44,8 @@ import Foundation
}
}
private static func sortedByDate<T: SortableArticle>(articles: [T],
sortDirection: ComparisonResult) -> [T] {
return articles.sorted { (article1, article2) -> Bool in
static func sortedByDate<T: SortableArticle>(articles: [T], sortDirection: ComparisonResult) -> [T] {
articles.sorted { (article1, article2) -> Bool in
if article1.sortableDate == article2.sortableDate {
return article1.sortableArticleID < article2.sortableArticleID
}
@@ -57,5 +56,4 @@ import Foundation
return article1.sortableDate < article2.sortableDate
}
}
}
+12 -12
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="24127" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="9cW-lu-HoC">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="24506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="9cW-lu-HoC">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24063"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
@@ -276,19 +276,19 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="SXs-NQ-y3U" customClass="VibrantTableViewCell" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="20" y="791" width="374" height="51.5"/>
<rect key="frame" x="20" y="791" width="374" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="SXs-NQ-y3U" id="BpI-Hz-KH2">
<rect key="frame" x="0.0" y="0.0" width="374" height="51.5"/>
<rect key="frame" x="0.0" y="0.0" width="374" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" text="Confirm Mark All as Read" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5tY-5k-v2g">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" ambiguous="YES" text="Confirm Mark All as Read" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5tY-5k-v2g">
<rect key="frame" x="20" y="15" width="191.5" height="21.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UOo-9z-IuL">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UOo-9z-IuL">
<rect key="frame" x="295" y="12" width="63" height="28"/>
<color key="onTintColor" name="primaryAccentColor"/>
<connections>
@@ -309,19 +309,19 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="EYf-v1-lNi" customClass="VibrantBasicTableViewCell" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="20" y="842.5" width="374" height="52.5"/>
<rect key="frame" x="20" y="843" width="374" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="EYf-v1-lNi" id="7nz-0Y-HaW">
<rect key="frame" x="0.0" y="0.0" width="374" height="52.5"/>
<rect key="frame" x="0.0" y="0.0" width="374" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Open Links in NetNewsWire" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wm4-Y1-7nX">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Open Links in NetNewsWire" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wm4-Y1-7nX">
<rect key="frame" x="20" y="18" width="267" height="21.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dhR-L2-PX3" userLabel="Open Links in NetNewsWire">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dhR-L2-PX3" userLabel="Open Links in NetNewsWire">
<rect key="frame" x="295" y="12.5" width="63" height="28"/>
<color key="onTintColor" name="primaryAccentColor"/>
<connections>
@@ -621,10 +621,10 @@
</objects>
<point key="canvasLocation" x="983" y="151"/>
</scene>
<!--Modern Timeline Customizer Table View Controller-->
<!--Timeline Customizer Table View Controller-->
<scene sceneID="6Fj-Lg-xsy">
<objects>
<tableViewController storyboardIdentifier="ModernTimelineCustomizerTableViewController" id="Tc9-Yc-Fvc" customClass="ModernTimelineCustomizerTableViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController storyboardIdentifier="TimelineCustomizerTableViewController" id="Tc9-Yc-Fvc" customClass="TimelineCustomizerTableViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="24" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" id="Q8W-CZ-Qtv">
<rect key="frame" x="0.0" y="0.0" width="414" height="746"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+1 -1
View File
@@ -202,7 +202,7 @@ final class SettingsViewController: UITableViewController {
case 3:
switch indexPath.row {
case 3:
let timeline = UIStoryboard.settings.instantiateController(ofType: ModernTimelineCustomizerTableViewController.self)
let timeline = UIStoryboard.settings.instantiateController(ofType: TimelineCustomizerTableViewController.self)
self.navigationController?.pushViewController(timeline, animated: true)
default:
break
@@ -0,0 +1,131 @@
//
// TimelineCustomizerTableViewController.swift
// NetNewsWire-iOS
//
// Created by Stuart Breckenridge on 21/08/2025.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
import UIKit
import Articles
final class TimelineCustomizerTableViewController: UITableViewController {
private var previewArticle: Article {
var components = DateComponents()
components.year = 1925
components.month = 4
components.day = 10
let calendar = Calendar.current
let date = calendar.date(from: components)!
return Article(accountID: "_testID",
articleID: "_testArticleID",
feedID: "_testFeedID",
uniqueID: UUID().uuidString,
title: "Chapter 1",
contentHTML: nil,
contentText: "In my younger and more vulnerable years my father gave me some advice that I’ve been turning over in my mind ever since. “Whenever you feel like criticizing any one,” he told me, “just remember that all the people in this world haven’t had the advantages that you’ve had.”",
markdown: nil,
url: nil,
externalURL: nil,
summary: nil,
imageURL: nil,
datePublished: date,
dateModified: nil,
authors: Set([Author(authorID: "_testAuthorID", name: "F. Scott Fitzgerald", url: nil, avatarURL: nil, emailAddress: nil)!]),
status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now))
}
override func viewDidLoad() {
super.viewDidLoad()
title = NSLocalizedString("Timeline Customizer", comment: "Timeline Customizer")
NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in
Task { @MainActor in
self?.userDefaultsDidChange()
}
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
tableView.reloadSections(IndexSet(integer: 2), with: .fade)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 4
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 { return NSLocalizedString("Icon Size", comment: "Icon Size")}
if section == 1 { return NSLocalizedString("Number of Lines", comment: "Number of Lines")}
if section == 2 { return NSLocalizedString("Preview with Icon", comment: "Previews") }
if section == 3 { return NSLocalizedString("Preview without Icon", comment: "Previews") }
return nil
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "IconSizeCell") as! ModernTimelineSliderCell
cell.sliderConfiguration = .iconSize
return cell
}
if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "NumberOfLinesCell") as! ModernTimelineSliderCell
cell.sliderConfiguration = .numberOfLines
return cell
}
if indexPath.section == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineIconFeedCell") as? MainTimelineIconFeedCell ?? MainTimelineIconFeedCell()
cell.cellData = MainTimelineCellData(article: previewArticle,
showFeedName: .byline,
feedName: "The Great Gatsby",
byline: "F. Scott Fitzgerald",
iconImage: IconImage(Assets.Images.nnwFeedIcon),
showIcon: true,
numberOfLines: AppDefaults.shared.timelineNumberOfLines,
iconSize: AppDefaults.shared.timelineIconSize)
cell.isPreview = true
return cell
}
if indexPath.section == 3 {
let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineFeedCell") as? MainTimelineFeedCell ?? MainTimelineFeedCell()
cell.cellData = MainTimelineCellData(article: previewArticle,
showFeedName: .byline,
feedName: "The Great Gatsby",
byline: "F. Scott Fitzgerald",
iconImage: nil,
showIcon: false,
numberOfLines: AppDefaults.shared.timelineNumberOfLines,
iconSize: AppDefaults.shared.timelineIconSize)
cell.isPreview = true
return cell
}
return UITableViewCell()
}
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return nil
}
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
return false
}
// MARK: - Notifications
func userDefaultsDidChange() {
tableView.reloadSections(IndexSet(integersIn: 2...3), with: .none)
}
}