Skip to content

Conversation

@lapfelix
Copy link
Contributor

@lapfelix lapfelix commented Jun 10, 2025

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

The UITraitCollection header is available on watchOS but UITraitCollection isn't

Fixes #3818

Summary by CodeRabbit

  • New Features
    • Added support for loading images on watchOS and other platforms without trait collection support by introducing an alternative image loading method.
  • Bug Fixes
    • Improved platform compatibility by ensuring trait collection-based image loading methods are not available on watchOS, preventing potential issues.

The UITraitCollection header is available on watchOS but UITraitCollection isn't
@coderabbitai
Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes update conditional compilation in SDAnimatedImage to exclude watchOS from methods using UITraitCollection, resolving compilation errors. An alternative method without the trait collection parameter is introduced for platforms lacking UITraitCollection support, ensuring compatibility with watchOS.

Changes

File(s) Change Summary
SDWebImage/Core/SDAnimatedImage.h,
SDWebImage/Core/SDAnimatedImage.m
Modified conditional compilation to exclude watchOS from trait collection-based methods.
Added alternative +imageNamed:inBundle: method for platforms without UITraitCollection support.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant SDAnimatedImage

    App->>SDAnimatedImage: imageNamed:inBundle:compatibleWithTraitCollection:
    alt Platform supports UITraitCollection and not watchOS
        SDAnimatedImage-->>App: Load image with trait collection
    else Platform is watchOS or lacks UITraitCollection
        App->>SDAnimatedImage: imageNamed:inBundle:
        SDAnimatedImage-->>App: Load image without trait collection
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix compilation error on watchOS due to unavailable UITraitCollection (#3818)

Poem

A hop and a skip, a code fix in sight,
WatchOS compiling—oh, what delight!
No more trait collection woes,
Now SDAnimatedImage simply goes.
With platform checks, the bugs are beat—
This rabbit’s work is quite complete! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d6e4fe and cf89b3a.

📒 Files selected for processing (2)
  • SDWebImage/Core/SDAnimatedImage.h (1 hunks)
  • SDWebImage/Core/SDAnimatedImage.m (1 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • SDWebImage/Core/SDAnimatedImage.m
  • SDWebImage/Core/SDAnimatedImage.h
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Unit Test (visionOS)
  • GitHub Check: Unit Test (macOS)
  • GitHub Check: Unit Test (iOS)
  • GitHub Check: Cocoapods Lint
  • GitHub Check: Cocoapods Demo
🔇 Additional comments (9)
SDWebImage/Core/SDAnimatedImage.h (3)

79-83: LGTM! Well-structured platform compatibility fix.

The conditional compilation properly excludes watchOS from UITraitCollection-dependent methods while providing appropriate fallback alternatives. This addresses the specific issue where the UITraitCollection header exists on watchOS but the class is unavailable.


79-83: Approved: Header properly matches implementation for platform compatibility.

The conditional compilation correctly declares different method signatures based on platform capabilities:

  • Platforms with UITraitCollection support (excluding watchOS) get the trait collection-aware method
  • watchOS and other platforms without UITraitCollection get the simpler alternative method

This ensures header-implementation consistency and resolves the watchOS build issue.


79-83: Excellent platform-specific method declaration handling.

The conditional compilation properly excludes the trait collection method from watchOS while providing an appropriate alternative. This matches the implementation changes and ensures API consistency across platforms.

SDWebImage/Core/SDAnimatedImage.m (6)

47-52: LGTM! Implementation properly matches header declarations.

The conditional compilation correctly excludes watchOS from the trait collection path and falls back to the simpler imageNamed:inBundle: method, maintaining consistency with the header file changes.


54-72: LGTM! Consistent platform-specific implementation.

The implementation correctly applies the same watchOS exclusion logic as the header, ensuring that trait collection-aware methods are disabled on watchOS while providing proper fallback behavior. The conditional compilation structure is well-organized and maintains backward compatibility.


47-47: Approved: Correctly excludes watchOS from trait collection routing.

The addition of && !SD_WATCH properly prevents the imageNamed: method from calling the trait collection variant on watchOS, where UITraitCollection class is unavailable despite the header being present.


54-54: Approved: Consistent conditional compilation for trait collection method.

The conditional compilation correctly excludes the trait collection-aware method implementation on watchOS, ensuring consistency with the header declaration and preventing build errors.


47-47: Correctly excludes watchOS from trait collection usage.

The addition of && !SD_WATCH ensures that watchOS builds fall back to the simpler imageNamed:inBundle: method, avoiding the UITraitCollection compilation error.


54-54: Properly guards trait collection method for watchOS.

This change ensures the imageNamed:inBundle:compatibleWithTraitCollection: method is not compiled on watchOS, where UITraitCollection class is unavailable despite the header being present.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dreampiggy
Copy link
Contributor

dreampiggy commented Jun 10, 2025

What Xcode version do you use and facing this issue ? Is this the new Xcode SDK ? (I don't know anything about Xcode 26)

Because the watchOS build is guaranteed by GitHub action pipeline, it should compile on Xcode 16

@dreampiggy dreampiggy added apple bug apple's bug cause our framework author's pain beta Apple Beta Software related labels Jun 10, 2025
@dreampiggy dreampiggy changed the title Fix watchOS build error with UITraitCollection [Xcode 26] - Fix watchOS build error with UITraitCollection in the new SDK Jun 10, 2025
@dreampiggy dreampiggy merged commit 2db93dc into SDWebImage:master Jun 10, 2025
6 of 8 checks passed
@dreampiggy dreampiggy added this to the 5.21.1 milestone Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apple bug apple's bug cause our framework author's pain beta Apple Beta Software related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package does not compile under WatchOS 26

2 participants