ResourceRewriterForXcode
Xcode 15+ plugin to migrate string-based asset literals to compile-time checked resource literals
Install / Use
/learn @idrougge/ResourceRewriterForXcodeREADME
Resource Rewriter for Xcode 15+
This plugin lets you automatically rewrite UIKit/SwiftUI image and colour instantations from unreliable string-based inits such as:
UIImage(named: "some icon")
Image("some icon")
UIColor(named: "light blue green")
Color("light blue green")
into ImageResource and ColorResource literals (as introduced in Xcode 15) such as:
UIImage(resource: .someIcon)
Image(.someIcon)
UIColor(resource: .lightBlueGreen)
Color(.lightBlueGreen)
Installation
- In Xcode, go to File → Add Package Dependencies and enter the URL for this repository.
- In the following popup, select Add to Target: None as the package is for running only in Xcode and not part of your app itself.
- In case your application is split into several packages, as is increasingly common, you also need to add the dependency to your package's
Package.swiftfile to process images in that package:
dependencies: [
.package(url: "https://github.com/idrougge/ResourceRewriterForXcode.git", branch: "main"),
]
Usage
After a rebuild, a secondary click on your project (or package) in the Project Navigator brings up a menu where you will now find the options "Rewrite image resource strings" and "Rewrite colour resource strings". Select that option and the target where you want your asset references to be fixed up.
Cleanup
As the UIImage(named:) init returns an optional and UIImage(resource:) does not, you may now have if let, guard let or nil coalescing (??) statements that are no longer necessary. These you will have to fix up by yourself as it is beyond the capabilities of a simple plugin.
If you have turned off generated asset symbols, go into your build settings and enable Generate Asset Symbols (ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOLS) or the resource names will not resolve.
After you are done, you are free to remove this dependency again, possibly introducing a linter rule forbidding calls to string-based asset inits.
Limitations
- Short-hand calls such as
image = .init(named: "Something")aren't handled. - Any image name built with string interpolation or concatenation is untouched as those must be resolved at run-time.
- The plugin strives to follow Xcode's pattern for translating string-based asset names into
ImageResource/ColorResourcenames but there may be cases where this does not match. Please open an issue in that case so it may added. - Functions or enums that return or accept string names, as well as wrapper functions or generated code must be rewritten manually if you wish to use
ImageResource/ColorResourcefor those. You may fork and customise this plugin if such uses permeate your project.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
