Introduced in Xcode 15, Apple now provides type-safe access to Color and Image assets. This is done with a compile-time extension providing properties for all available assets. These can be access using new initialisers on Color and Image types (in UIKit, SwiftUI, and AppKit).
Given the enhancements this provides to safety (ensuring codebases only reference resources which actually exist), I think it would be a good rule to have in most codebases to use these new extensions -- thus having it available in this tool would be beneficial.
This rule becomes slightly more complicated when you take into account non-static strings (where the named value is either a variable, or a string containing an interpolated variable).
// Non Triggering
UIImage("flag/\(countryCode)")
let someStringFromViewModel = model.imageName
Color(someStringFromViewModel)
// Triggering
Color(isDarkMode ? "textDark" : "textLight")
Logic
It's worth noting the property name generated by Xcode is not 100% the same as the asset name (used in the named variable). Some known examples:
Description
Introduced in Xcode 15, Apple now provides type-safe access to Color and Image assets. This is done with a compile-time extension providing properties for all available assets. These can be access using new initialisers on Color and Image types (in UIKit, SwiftUI, and AppKit).
Given the enhancements this provides to safety (ensuring codebases only reference resources which actually exist), I think it would be a good rule to have in most codebases to use these new extensions -- thus having it available in this tool would be beneficial.
Examples
Non Triggering Examples
This rule becomes slightly more complicated when you take into account non-static strings (where the named value is either a variable, or a string containing an interpolated variable).
Logic
It's worth noting the property name generated by Xcode is not 100% the same as the asset name (used in the named variable). Some known examples:
some_blue
=someBlue
someBlueColor
=someBlue