Skip to content

fix(PlatformImage): use a typed UIImage protocol and pick the image class by system - #1248

Draft
cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:rfc-uiimage-bridge
Draft

cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:rfc-uiimage-bridge

Conversation

@cristim

@cristim cristim commented Nov 4, 2026 •

Copy link
Copy Markdown

Summary

RFC, draft, unbuilt.

  • Replace the NSObject category that declares UIImage selectors with a protocol.
  • Look up the platform image class per call by the requested system (NSImage for AppKit, UIImage otherwise) instead of caching one class in statics.

Impact to review: on macOS with a non-AppKit system the class changes from NSImage to UIImage, which fixes an unrecognized-selector path but raises if UIKit is not loaded. iOS and visionOS only lose the cache.

Verification

Run: the commit cherry-picks cleanly onto current main; a cold review read the call sites. Not run: no compiler was available, so this was not compiled. CONTRIBUTING.md asks for an issue first for large work; this is one concern. Related RFC draft: #1246.

…SObject category

The UIImage selectors were declared as a category on NSObject, which adds
them to NSObject and NSImage for every translation unit that sees the header.
Declare a protocol and cast to it at the call sites instead. The class lookup
now also honours the requested system (NSImage for AppKit, UIImage
otherwise) and is no longer cached in statics.

(cherry picked from commit 9a67fb2)
@cristim cristim changed the title refactor(PlatformImage): use a typed UIImage protocol instead of an NSObject category fix(PlatformImage): use a typed UIImage protocol and pick the image class by system Nov 4, 2026
@cristim

cristim commented Nov 4, 2026

Copy link
Copy Markdown
Author

Cold review: FIX-NEEDED on wording, now fixed in the PR title and body: this is a behaviour fix (macOS with a non-AppKit system now selects UIImage), not a pure refactor. Code otherwise reads correct (system is a parameter in scope). Not compiled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant