diff --git a/.swiftlint.yml b/.swiftlint.yml index bcbf464..4954207 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -10,6 +10,10 @@ included: - Sources +# SwiftLint analyze 的 unused_import 对系统框架 import(Foundation/UIKit/Security 等)存在已知误报: +# swiftc 编译日志 0 条 unused import 警告,删除这些 import 会导致编译失败 +# (如 STSecurityModels 依赖 Foundation 的 Date/TimeInterval,见 .github/workflows/swift.yml 的 Analyze 步骤)。 +# 该规则已整体禁用(见下方 analyzer_rules),故无需在此按文件排除。 excluded: - Sources/STMarkdown/Resources - .build @@ -67,8 +71,15 @@ opt_in_rules: force_cast: error # as! 直接 error analyzer_rules: - - unused_import - - unused_declaration + # 本仓库是底层公用库:大量 public/internal/fileprivate API 提供给宿主 App / Example 模块调用, + # SwiftLint analyze 的 analyzer_rules 只扫描包内 99 个文件,看不到外部调用方, + # 会系统性误报 unused_import 与 unused_declaration(且 swiftc 编译日志证明 import 必需)。 + # 验证依据见下。故整体禁用这两个 analyzer 规则。 + # - unused_import : 系统框架 import(Foundation/UIKit/Security 等)被误判为冗余, + # clean build 的 swiftc 编译日志 unused import 警告为 0 条,删除会导致编译失败。 + # - unused_declaration: 对外暴露的库 API 在包内无引用,被误判为未使用。 + # - unused_import + # - unused_declaration # 公开 API 文档缺失检查:存量 882 个未清零,暂移出 opt_in_rules(见 disabled_rules), # 待文档补齐专项后再恢复并重新纳入 --strict 门槛。仅检查 public 级别。 diff --git a/Sources/STBaseView/STBaseView.swift b/Sources/STBaseView/STBaseView.swift index f2f9ee7..43f4cf6 100644 --- a/Sources/STBaseView/STBaseView.swift +++ b/Sources/STBaseView/STBaseView.swift @@ -404,7 +404,7 @@ open class STBaseView: UIView { guard self.layoutMode == .scroll else { return } guard appearing || self.baseContentInset != nil else { return } guard let userInfo = note.userInfo, self.enableScrollViewKeyboardAdjustment else { - if !appearing, let baseContent = self.baseContentInset { + if !appearing, self.baseContentInset != nil { // 键盘调整被关闭,但仍需还原已注入的 inset。 self.restoreBaseInsets() } diff --git a/Sources/STConfig/STOrientationManager.swift b/Sources/STConfig/STOrientationManager.swift index 8c767ee..cf6f9f4 100644 --- a/Sources/STConfig/STOrientationManager.swift +++ b/Sources/STConfig/STOrientationManager.swift @@ -32,23 +32,13 @@ public final class STOrientationManager { } private func requestGeometryUpdate(_ orientations: UIInterfaceOrientationMask, in windowScene: UIWindowScene?) { - let targetWindowScene = windowScene ?? self.activeWindowScene() - if #available(iOS 16.0, *), let targetWindowScene { - targetWindowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientations)) { error in - STLog("[STOrientationManager] requestGeometryUpdate failed: \(error.localizedDescription)") - } - } else { - UIDevice.current.setValue(self.preferredOrientation(for: orientations).rawValue, forKey: "orientation") + guard let targetWindowScene = windowScene ?? self.activeWindowScene() else { + STLog("[STOrientationManager] No active UIWindowScene found; cannot request geometry update.") + return + } + targetWindowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientations)) { error in + STLog("[STOrientationManager] requestGeometryUpdate failed: \(error.localizedDescription)") } - UIViewController.attemptRotationToDeviceOrientation() - } - - private func preferredOrientation(for orientations: UIInterfaceOrientationMask) -> UIInterfaceOrientation { - if orientations.contains(.portrait) { return .portrait } - if orientations.contains(.landscapeLeft) { return .landscapeLeft } - if orientations.contains(.landscapeRight) { return .landscapeRight } - if orientations.contains(.portraitUpsideDown) { return .portraitUpsideDown } - return .portrait } private func activeWindowScene() -> UIWindowScene? { diff --git a/Sources/STHUD/STAlertController.swift b/Sources/STHUD/STAlertController.swift index bff6f2c..a3bae1a 100644 --- a/Sources/STHUD/STAlertController.swift +++ b/Sources/STHUD/STAlertController.swift @@ -55,7 +55,7 @@ private enum STAlertLayoutConstant { static let titleMessageSpacing: CGFloat = 10 } -public enum STAlertBtnClickType { +public enum STAlertBtnClickType: String { case btnClick case leftBtnClick case rightBtnClick @@ -300,7 +300,7 @@ open class STAlertController: UIViewController { handler(true, sender.titleLabel?.text ?? "") } } else { - if let type = sender.identifier as? STAlertBtnClickType, type == .leftBtnClick { + if sender.stringIdentifier == STAlertBtnClickType.leftBtnClick.rawValue { if let handler = self.alertInfo.buttonHandlers.first { handler(true, sender.titleLabel?.text ?? "") } @@ -335,7 +335,7 @@ open class STAlertController: UIViewController { }() let btn = self.createBtn(action: singleAction) btn.tag = 0 - btn.identifier = STAlertBtnClickType.btnClick + btn.stringIdentifier = STAlertBtnClickType.btnClick.rawValue btn.addTarget(self, action: #selector(alertButtonClick), for: .touchUpInside) self.alertView.addSubview(btn) self.view.addConstraints([ @@ -370,7 +370,7 @@ open class STAlertController: UIViewController { }() let leftBtn = self.createBtn(action: leftAction) leftBtn.tag = 0 - leftBtn.identifier = STAlertBtnClickType.leftBtnClick + leftBtn.stringIdentifier = STAlertBtnClickType.leftBtnClick.rawValue leftBtn.addTarget(self, action: #selector(alertButtonClick), for: .touchUpInside) self.alertView.addSubview(leftBtn) @@ -390,7 +390,7 @@ open class STAlertController: UIViewController { }() let rightBtn = self.createBtn(action: rightAction) rightBtn.tag = 1 - rightBtn.identifier = STAlertBtnClickType.rightBtnClick + rightBtn.stringIdentifier = STAlertBtnClickType.rightBtnClick.rawValue rightBtn.addTarget(self, action: #selector(alertButtonClick), for: .touchUpInside) self.alertView.addSubview(rightBtn) self.view.addConstraints([