Rename or find where a custom Color Asset has been used in Xcode

Now with Dark Mode I have been creating color assets to manage dark mode colors, but sometimes I think of a more semantic name for a certain color after I have used it in multiple places and I was wondering if there is a way to find where a color has been used even if I have to go and manually changed them, I'm not really looking for an automatic solution.


Is there a way to rename or find all of the instances where a custom color asset has been used in Xcode?


Thanks!

Answered by Claude31 in 390570022

Sorry, I mistook. It does cause any error, nor at compile nor at execution.


BUT, if you open the storyboard as Source code, you will be able to search by name.


PS: Save a copy of the project,


Return to the original project.

open storyboard as Source code, (you may copy it to a text file).

Now, when you search colorname, you'll get a refernce of an object (need to search a bit, before the <subviews> section.

From there you know who is using the color !


Or if you just want to rename, do it in the textfile and reopen as storyboard (don't forget to change the asset name).

That's why you need to work on a copy, in case something turn wrong and you corrupt your storyboard.

In such a case, I use a "brute force search and replace".


Change the name of the color asset.

That will cause compilation error.

And let you modify.

Oh, it does throw a compilation error when you picked the asset directly in the interface builder in the attributes inspector? If that's the case It's all I need.

Accepted Answer

Sorry, I mistook. It does cause any error, nor at compile nor at execution.


BUT, if you open the storyboard as Source code, you will be able to search by name.


PS: Save a copy of the project,


Return to the original project.

open storyboard as Source code, (you may copy it to a text file).

Now, when you search colorname, you'll get a refernce of an object (need to search a bit, before the <subviews> section.

From there you know who is using the color !


Or if you just want to rename, do it in the textfile and reopen as storyboard (don't forget to change the asset name).

That's why you need to work on a copy, in case something turn wrong and you corrupt your storyboard.

Or....select the storyboard, right click, choose to open as source, cmd.-F, then search - that way, if you do mod it, it will retain proper formatting, being sure as always to have a project backup, as you suggest 😉, and to go back to the default storyboard view, right click and choose to open as IB-Storyboard.

The "Brute force and replace" didnt help.. However, with a little help of our bash friend :

Code Block `
cd _Root_Project_
grep -rl "my_color_asset_name" .
`

it returns the list of all files in which color are used, including storyboard, xibs etc..
You can drag and drop project folder to Sublime Text and search there (using cmd + shift + f).

This will give you the list of files that are using the color.
Rename or find where a custom Color Asset has been used in Xcode
 
 
Q