It is egregious that Xcode's find/replace does not properly support Interface Builder files. Sometimes you can find but not replace (fonts). Other times you can't even find (color sets).
So far I've always had to solve this by using a combination of find/grep and sed, modifying the interface builder files directly. This can be risky. Make sure you've committed changes and generally trust yourself.
To start off only reviewing the changes to be made without any file modifications, I've used the following command in the root of my project directory:
find . -type f \( -name '*.xib' -or -name '*.storyboard' \) \
-exec echo {} \; \
-exec sed -E -n 's/([cC]olor.*)name="oldColorName"/\1name="newColorName"/p' {} \;
This prints each file found along with any changes that would be made to the file according to the sed pattern. The pattern is complex to guarantee matches related to color usage. If your color name is unique enough that you're not concerned with false positives, you can remove it and simply pattern match the name itself: 's/oldColorName/newColorName/p'
.
When ready to apply the changes, execute the sed command in-place on the files with:
find . -type f \( -name '*.xib' -or -name '*.storyboard' \) \
-exec sed -E -i '' 's/([cC]olor.*)name="oldColorName"/\1name="newColorName"/' {} \;
Note that printing was deliberately removed here. Don't attempt to keep -n
and /p
in your command. That's not how sed works. You can review the changes in your diff tool of choice at this point anyway. Discard them if it didn't do what you expected.
Also, you can perform this change even when the new color set has different color values, which is handy when updating a color in addition to renaming it. When you next open the Interface Builder file in Xcode, the color value will automatically update in the XML to match the value corresponding to the changed name.