Skip to content

Remove unnecessary UIKit imports - #25812

Open
jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/remove-unused-uikit-imports
Open

Remove unnecessary UIKit imports#25812
jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/remove-unused-uikit-imports

Conversation

@jkmassel

@jkmassel jkmassel commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Removes import UIKit from files that reference no UIKit symbol — a follow-up to the cross-platform module split in #25344, where a stray UIKit import is what keeps a file (or an entire module) from compiling on platforms without UIKit.

Summary

  • 39 files; the repo-wide import UIKit count drops from 946 → 907.
  • Imports only — no behavior change, and nothing visual to screenshot.
  • Swept WordPress/, Modules/, Sources/, and Tests/. Every candidate was found by a heuristic pass (no UI* identifier, no UIKit-only NS* type, no UIKit extension-on-Foundation call) and then read individually to confirm.

Changes

Action Files Rationale
import UIKitimport Foundation 26 The file uses Foundation types (URL, NSCoder, NSLocalizedString, SortDescriptor, HTTPCookieStorage, …) that UIKit was only re-exporting
import UIKit removed 12 Foundation is already imported, or the file uses only SwiftUI / CoreLocation / UserNotifications / the standard library
import UIKitimport QuartzCore 1 CATransaction+Extension.swiftCATransaction is Core Animation, not UIKit; a plain Foundation swap would not compile

UIKit re-exports Foundation, so the Foundation swaps are load-bearing — deleting the import outright would break any file leaning on it for URL/NSCoder/etc. SwiftUI, XCTest, CoreLocation, and WordPressData do not reliably re-export Foundation.

What we deliberately left alone

A first pass caught 17 more files that compile fine without import UIKit but were left untouched on purpose: each one declares or extends a type whose superclass chain roots in UIKit, so the dependency is real — it is inherited rather than spelled. PeopleRoleBadgeLabel is the clearest example:

class PeopleRoleBadgeLabel: BadgeLabel {   // BadgeLabel: UILabel
    override init(frame: CGRect) { ... }   // UIView
    private func setupView() {
        adjustsFontSizeToFitWidth = true   // UILabel
        layer.cornerRadius = .DS.Radius.small   // UIView
    }
}

Nothing in that file names a UI* symbol, so the compiler does not need the import — Swift only requires a module import to name its types, and inherited member lookup walks the superclass chain regardless. But dropping it would buy nothing: the file can never compile without UIKit, because its superclass is a UILabel. It would only hide a real dependency and break the next edit that names a UIKit type.

Same reasoning for the other 16 — WebKitViewController / TemplatePreviewViewController / BaseRestoreStatusViewController subclasses (all → UIViewController), ReaderBaseHeaderView subclasses (→ UIView), and extensions on WebKitViewController, ListTableViewCell, and StatsViewController.

So the rule this PR applies is "the file has no UIKit dependency," not "the file names no UIKit symbol." Every one of the 39 files here is genuinely UIKit-free.

Test plan

  • xcodebuild buildWordPress scheme, iOS Simulator → BUILD SUCCEEDED, 0 errors (all 33 app/module source files)
  • xcodebuild build-for-testingWordPressUnitTests plan → TEST BUILD SUCCEEDED, 0 errors (the 6 test files, across the WordPressTest, WordPressKitTests, and AsyncImageKitTests targets)
  • CI green — build #34144, 28/28 checks

Related

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34144
VersionPR #25812
Bundle IDorg.wordpress.alpha
Commite89ab07
Installation URL6ng39u4iggrh8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34144
VersionPR #25812
Bundle IDcom.jetpack.alpha
Commite89ab07
Installation URL7ns49jk18aro0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@jkmassel
jkmassel force-pushed the jkmassel/remove-unused-uikit-imports branch from df2edc9 to 8894295 Compare September 1, 2026 23:25
@jkmassel
jkmassel requested a review from crazytonyli September 1, 2026 23:29
@jkmassel jkmassel self-assigned this Sep 1, 2026
@jkmassel jkmassel added this to the 27.3 milestone Sep 1, 2026
Sweep files that import UIKit but reference no UIKit symbol. Where the
import only provided Foundation via re-export, switch to `import
Foundation`; CATransaction+Extension moves to `import QuartzCore` since
CATransaction is Core Animation. Imports only, no behavior change.

Files that declare or extend a UIKit-rooted type keep their import even
though nothing in them names a UI* symbol — the dependency is real, it is
just inherited rather than spelled.

Follow-up to #25344.
@jkmassel
jkmassel force-pushed the jkmassel/remove-unused-uikit-imports branch from 8894295 to e89ab07 Compare September 1, 2026 23:43
@jkmassel
jkmassel marked this pull request as ready for review September 1, 2026 23:58
@jkmassel
jkmassel added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants