Skip to content

Commit

Permalink
Fix Warnings from iOS 17 SDK and SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed Oct 18, 2023
1 parent 65cffa5 commit 4bd63d7
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 129 deletions.
12 changes: 7 additions & 5 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@ disabled_rules:
- todo
- trailing_comma
- type_name
# - colon
# - comma
# - control_statement

opt_in_rules: # some rules are only opt-in
# - empty_count
# Find all the available rules by running:
# swiftlint rules

included: # paths to include during linting. `--path` is ignored if present.
- OBAKit
- OBAKitCore
- TodayView

excluded: # paths to ignore during linting. Takes precedence over `included`.
- OBAKit/SwipeCellKit
- OBAKitCore/Models/Protobuf/gtfs-realtime.pb.swift

force_try:
excluded:
- OBAKitTests

function_body_length:
excluded:
- OBAKitTests

file_length:
warning: 900
error: 1000

type_body_length:
warning: 900
error: 1000
4 changes: 2 additions & 2 deletions OBAKit/Bookmarks/Formatters+BookmarkArrival.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ extension Formatters {

let formatString: String
switch (secondArrDepIsArrival, thirdArrDepIsArrival) {
case (true, true): formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingtwoarrivals_fmt", value: "Following two arrivals in %d minutes and %d minutes.", comment: "Voiceover text describing the two additional arrivals in the near-future, regardless of realtime data availability.")
case (false, false):formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingtwodepartures_fmt", value: "Following two departures in %d minutes and %d minutes.", comment: "Voiceover text describing the two additional departures in the near-future, regardless of realtime data availability.")
case (true, true): formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingtwoarrivals_fmt", value: "Following two arrivals in %d minutes and %d minutes.", comment: "Voiceover text describing the two additional arrivals in the near-future, regardless of realtime data availability.")
case (false, false): formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingtwodepartures_fmt", value: "Following two departures in %d minutes and %d minutes.", comment: "Voiceover text describing the two additional departures in the near-future, regardless of realtime data availability.")
case (true, false): formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingarrivalthendeparture_fmt", value: "Following arrival in %d minutes and departure in %d minutes.", comment: "Voiceover text describing an arrival, then a departure in the near-future, regardless of realtime data availability.")
case (false, true): formatString = OBALoc("voiceover.bookmarkarrivaldata.value.followingdeparturethenarrival_fmt", value: "Following departure in %d minutes and arrival in %d minutes.", comment: "Voiceover text describing a departure, then an arrival in the near-future, regardless of realtime data availability.")
}
Expand Down
28 changes: 0 additions & 28 deletions OBAKit/Controls/Buttons/BorderedButton.swift

This file was deleted.

15 changes: 1 addition & 14 deletions OBAKit/Controls/FloatingPanel/FloatingPanelTitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,7 @@ class FloatingPanelTitleView: UIView {

// MARK: - Close Button

public let closeButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(Icons.closeCircle, for: .normal)
button.accessibilityLabel = Strings.close
button.setContentHuggingPriority(.required, for: .horizontal)
button.setContentCompressionResistancePriority(.required, for: .vertical)
NSLayoutConstraint.activate([
button.heightAnchor.constraint(equalToConstant: 40.0),
button.widthAnchor.constraint(equalToConstant: 40.0)
])
button.imageEdgeInsets = UIEdgeInsets(top: ThemeMetrics.padding, left: ThemeMetrics.padding, bottom: ThemeMetrics.padding, right: ThemeMetrics.padding)
return button
}()
public let closeButton = UIButton.buildCloseButton()

private lazy var closeButtonWrapper: UIView = {
let wrapper = closeButton.embedInWrapperView(setConstraints: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct EmptyDataSetItem: OBAListViewItem {
icon = UIImage(systemName: "wifi.slash")
case .captivePortal:
icon = UIImage(systemName: "wifi.exclamationmark")
case .noResponseBody, .requestFailure, .invalidContentType :
case .noResponseBody, .requestFailure, .invalidContentType:
icon = UIImage(systemName: "bolt.horizontal.circle")
case .requestNotFound:
icon = UIImage(systemName: "questionmark.square.dashed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension OBAListView {
icon = UIImage(systemName: "wifi.slash")
case .captivePortal:
icon = UIImage(systemName: "wifi.exclamationmark")
case .noResponseBody, .requestFailure, .invalidContentType :
case .noResponseBody, .requestFailure, .invalidContentType:
icon = UIImage(systemName: "bolt.horizontal.circle")
case .requestNotFound:
icon = UIImage(systemName: "questionmark.square.dashed")
Expand Down
8 changes: 5 additions & 3 deletions OBAKit/Controls/ProgressHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import UIKit

// swiftlint:disable comment_spacing control_statement cyclomatic_complexity no_space_in_method_call unused_closure_parameter notification_center_detachment file_length opening_brace switch_case_alignment
// swiftlint:disable comment_spacing control_statement cyclomatic_complexity no_space_in_method_call unused_closure_parameter notification_center_detachment file_length opening_brace switch_case_alignment for_where

//-------------------------------------------------------------------------------------------------------------------------------------------------
public enum AnimationType {
Expand Down Expand Up @@ -338,7 +338,7 @@ public class ProgressHUD: UIView {
private func setupBackground(_ interaction: Bool) {

if (viewBackground == nil) {
let mainWindow = UIApplication.shared.windows.first ?? UIWindow()
let mainWindow = UIApplication.shared.keyWindowFromScene ?? UIWindow()
viewBackground = UIView(frame: self.bounds)
mainWindow.addSubview(viewBackground!)
}
Expand Down Expand Up @@ -550,7 +550,7 @@ public class ProgressHUD: UIView {
let inputSetContainerView = NSClassFromString("UIInputSetContainerView"),
let inputSetHostView = NSClassFromString("UIInputSetHostView") {

for window in UIApplication.shared.windows {
for window in UIApplication.shared.activeWindows {
if window.isKind(of: keyboardWindowClass) {
for firstSubView in window.subviews {
if firstSubView.isKind(of: inputSetContainerView) {
Expand Down Expand Up @@ -1270,3 +1270,5 @@ private class ProgressView: UIView {
labelPercentage.text = "\(Int(value*100))%"
}
}

// swiftlint:enable comment_spacing control_statement cyclomatic_complexity no_space_in_method_call unused_closure_parameter notification_center_detachment file_length opening_brace switch_case_alignment for_where
2 changes: 1 addition & 1 deletion OBAKit/Extensions/DispatchExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OBAKitCore

private var throttleWorkItems = [AnyHashable: DispatchWorkItem]()
private var lastDebounceCallTimes = [AnyHashable: DispatchTime]()
private let nilContext: AnyHashable = arc4random()
private let nilContext: AnyHashable = UInt32.random(in: UInt32.min...UInt32.max)

public extension DispatchQueue {
/**
Expand Down
47 changes: 47 additions & 0 deletions OBAKit/Extensions/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//

import UIKit
import OBAKitCore

// MARK: - UIButton

Expand All @@ -19,13 +20,59 @@ public extension UIButton {
button.setImage(Icons.chevron, for: .normal)
return button
}

class func buildCloseButton() -> UIButton {
var configuration = UIButton.Configuration.borderless()
configuration.image = Icons.closeCircle
configuration.contentInsets = NSDirectionalEdgeInsets(top: ThemeMetrics.padding, leading: ThemeMetrics.padding, bottom: ThemeMetrics.padding, trailing: ThemeMetrics.padding)

let button = UIButton(configuration: configuration)
button.translatesAutoresizingMaskIntoConstraints = false
button.setContentHuggingPriority(.required, for: .horizontal)
button.setContentCompressionResistancePriority(.required, for: .vertical)
NSLayoutConstraint.activate([
button.heightAnchor.constraint(equalToConstant: 40.0),
button.widthAnchor.constraint(equalToConstant: 40.0)
])

button.accessibilityLabel = Strings.close

return button
}
}

// MARK: - UITraitEnvironment Accessibility

extension UITraitEnvironment {
/// For OneBusAway, `isAccessibility` is anything equal to or larger than `.extraLarge`.
var isAccessibility: Bool {
let contentSize = traitCollection.preferredContentSizeCategory
return contentSize >= .extraLarge
}
}

// MARK: - UIApplication

extension UIApplication {

/// Extracts the key window from the receiver's connected scenes.
///
/// A replacement for the deprecated `UIApplication.windows` property.
var keyWindowFromScene: UIWindow? {
activeWindows.first(where: \.isKeyWindow)
}

var activeWindows: [UIWindow] {
// Get connected scenes
let windows = self.connectedScenes
// Keep only active scenes, onscreen and visible to the user
.filter { $0.activationState == .foregroundActive }
// Keep only the first `UIWindowScene`
.first(where: { $0 is UIWindowScene })
// Get its associated windows
.flatMap({ $0 as? UIWindowScene })?.windows

return windows ?? []
}

}
3 changes: 3 additions & 0 deletions OBAKit/Mapping/SearchListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class SearchListViewController: UIViewController, Scrollable, OBAListViewDataSou
}

var sections = delegate.searchInteractor.searchModeObjects(text: delegate.searchBarText)

// swiftlint:disable unused_enumerated
for (idx, _) in sections.enumerated() {
sections[idx].configuration.backgroundColor = .clear
}
// swiftlint:enable unused_enumerated

return sections
}
Expand Down
2 changes: 1 addition & 1 deletion OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public class Application: CoreApplication, PushServiceDelegate {

/// Provides access the topmost view controller in the app, if one exists.
private var topViewController: UIViewController? {
delegate?.uiApplication?.windows.first?.topViewController
delegate?.uiApplication?.keyWindowFromScene?.topViewController
}

@objc public func application(_ application: UIApplication, didFinishLaunching options: [AnyHashable: Any]) {
Expand Down
5 changes: 5 additions & 0 deletions OBAKit/Search/SearchInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ class SearchInteractor: NSObject {
/// Creates a Quick Search section
/// - Parameter searchText: The text that the user is searching for
private func quickSearchSection(searchText: String) -> OBAListViewSection {

// swiftlint:disable large_tuple

var quickSearchTypes: [(SearchType, String, UIImage)] = [
(.route, OBALoc("search_interactor.quick_search.route_prefix", value: "Route:", comment: "Quick search prefix for Route."), Icons.route),
(.address, OBALoc("search_interactor.quick_search.address_prefix", value: "Address:", comment: "Quick search prefix for Address."), Icons.place),
(.stopNumber, OBALoc("search_interactor.quick_search.stop_prefix", value: "Stop:", comment: "Quick search prefix for Stop."), Icons.stop)
]

// swiftlint:enable large_tuple

if let delegate = delegate, delegate.isVehicleSearchAvailable {
quickSearchTypes.append((.vehicleID, OBALoc("search_interactor.quick_search.vehicle_prefix", value: "Vehicle:", comment: "Quick search prefix for Vehicle."), Icons.busTransport))
}
Expand Down
2 changes: 2 additions & 0 deletions OBAKit/ServiceAlerts/ServiceAlertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,5 @@ fileprivate class HTMLBuilder {
HTML.append(tag.closing)
}
}

// swiftlint:enable function_body_length
23 changes: 0 additions & 23 deletions OBAKit/Settings/OBAKit_Credits.plist
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,6 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</string>
<key>SwipeCellKit</key>
<string>MIT License
Copyright (c) 2017 Jeremy Koch
http://jerkoch.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &quot;Software&quot;), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
2 changes: 2 additions & 0 deletions OBAKit/Stops/OccupancyStatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,5 @@ struct OccupancyStatusView_Previews: PreviewProvider {
}

#endif

// swiftlint:enable no_fallthrough_only
2 changes: 1 addition & 1 deletion OBAKit/Trip/TripFloatingPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class TripFloatingPanelController: UIViewController,
self.separatorView.isHidden = false
self.stopArrivalView.normalInfoStack.forEach { $0.isHidden = isAccessibility }
self.stopArrivalView.accessibilityInfoStack.forEach { $0.isHidden = !isAccessibility }
case .hidden: fallthrough
case .hidden: break
default: break
}
}
Expand Down
3 changes: 2 additions & 1 deletion OBAKitCore/Collections/EmptyDataSetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class EmptyDataSetView: UIView {
}

// MARK: - Constants

fileprivate static let DefaultColor = ThemeColors.shared.secondaryLabel

var topConstraint: NSLayoutConstraint!
Expand Down Expand Up @@ -55,8 +56,8 @@ public class EmptyDataSetView: UIView {
}
}

/// Configuration for the button. Set to `nil` to hide the button. See `ButtonConfig.init` for additional details.
// MARK: - UI

public var alignment: EmptyDataSetAlignment = .center {
didSet {
layoutView()
Expand Down
6 changes: 4 additions & 2 deletions OBAKitCore/DataMigration/DataMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import Foundation

// swiftlint:disable cyclomatic_complexity function_body_length

public protocol DataMigrationDelegate: AnyObject {
func migrate(recentStop: Stop) async throws
func migrate(userID: String) async throws
Expand Down Expand Up @@ -81,7 +83,6 @@ public class DataMigrator {
return extractor.hasDataToMigrate
}

// swiftlint:disable cyclomatic_complexity function_body_length
/// Perform migration, with the specified `parameters`, against the provided `apiService`. See source code for implementation details.
/// - precondition: `parameters.regionIdentifier` must be equal to `apiService.configuration.regionIdentifier`, or else this will throw an error.
/// - precondition: `extractor.hasDataToMigrate == true`, or else this will throw an error.
Expand Down Expand Up @@ -242,7 +243,6 @@ public class DataMigrator {
return results
}

// swiftlint:disable syntactic_sugar
/// An `NSURLError` is considered a "critical error".
nonisolated func throwCriticalErrorIfAny<ResultType>(_ results: Dictionary<some Hashable, Result<ResultType, Error>>.Values) throws {
for result in results {
Expand Down Expand Up @@ -377,3 +377,5 @@ public class DataMigrator {
}
}
}

// swiftlint:enable cyclomatic_complexity function_body_length
12 changes: 2 additions & 10 deletions OBAKitCore/Extensions/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//

import UIKit
import UniformTypeIdentifiers
import MobileCoreServices

// MARK: - Scrollable
Expand Down Expand Up @@ -351,15 +352,6 @@ extension UILayoutPriority {
// MARK: - UIPasteboard

public extension UIPasteboard {

private var UTTypeRTF: String {
(kUTTypeRTF as String)
}

private var UTTypePlainText: String {
(kUTTypeUTF8PlainText as String)
}

/// A convenience method for setting the pasteboard to an attributed string as RTF data.
/// - Parameter attributedString: The attributed string to which the pasteboard will be set.
/// - Note: adapted from [https://stackoverflow.com/a/21911997/136839](https://stackoverflow.com/a/21911997/136839)
Expand All @@ -372,7 +364,7 @@ public extension UIPasteboard {
let rtfString = NSString(data: rtfData, encoding: String.Encoding.utf8.rawValue)
else { return }

items = [[UTTypeRTF: rtfString, UTTypePlainText: attributedString.string]]
items = [[UTType.rtf.identifier: rtfString, UTType.plainText.identifier: attributedString.string]]
}
}

Expand Down
Loading

0 comments on commit 4bd63d7

Please sign in to comment.