You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-10Lines changed: 14 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,18 @@
1
1
# Resource Rewriter for Xcode 15+
2
2
3
-
This plugin lets you automatically rewrite UIKit/SwiftUI image instantations from unreliable string-based inits such as:
3
+
This plugin lets you automatically rewrite UIKit/SwiftUI image and colour instantations from unreliable string-based inits such as:
4
4
```swift
5
-
UIImage(named: "some image")
6
-
Image("some image")
5
+
UIImage(named: "some icon")
6
+
Image("some icon")
7
+
UIColor(named: "light blue green")
8
+
Color("light blue green")
7
9
```
8
-
into `ImageResource` literals (as introduced in Xcode 15) such as:
10
+
into `ImageResource`and `ColorResource`literals (as introduced in Xcode 15) such as:
9
11
```swift
10
-
UIImage(resource: .someImage)
11
-
Image(.someImage)
12
+
UIImage(resource: .someIcon)
13
+
Image(.someIcon)
14
+
UIColor(resource: .lightBlueGreen)
15
+
Color(.lightBlueGreen)
12
16
```
13
17
14
18
## Installation
@@ -27,7 +31,7 @@ dependencies: [
27
31
28
32
## Usage
29
33
30
-
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 option "Rewrite image resource strings". Select that option and the target where you want your image references to be fixed up.
34
+
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.
@@ -37,11 +41,11 @@ As the `UIImage(named:)` init returns an optional and `UIImage(resource:)` does
37
41
38
42
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.
39
43
40
-
After you are done, you are free to remove this dependency again, possibly introducing a linter rule forbidding calls to string-based image inits.
44
+
After you are done, you are free to remove this dependency again, possibly introducing a linter rule forbidding calls to string-based asset inits.
41
45
42
46
## Limitations
43
47
44
48
* Short-hand calls such as `image = .init(named: "Something")` aren't handled.
45
49
* Any image name built with string interpolation or concatenation is untouched as those must be resolved at run-time.
46
-
* The plugin strives to follow Xcode's pattern for translating string-based image names into `ImageResource` names but there may be cases where this does not match. Please open an issue in that case so it may added.
47
-
* 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` for those. You may fork and customise this plugin if such uses permeate your project.
50
+
* The plugin strives to follow Xcode's pattern for translating string-based asset names into `ImageResource/ColorResource` names but there may be cases where this does not match. Please open an issue in that case so it may added.
51
+
* 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/ColorResource` for those. You may fork and customise this plugin if such uses permeate your project.
0 commit comments