0

I have a well advanced project in Swift on Xcode. After a while I decided to add a custom property (to catch a UIColor) to UIButton Class by subclassing it. But I already have a whole bunch of buttons in my Interface Builder set and programmatically in my project itself.

Is there a clean way to change each instances of my old UIButton Class, in IB and in the project files, to my new one at once without messing everything ? Hope I have been clear... ;) Thanks a lot

Lostania
  • 145
  • 8
  • 1
    You may be able to use the Refactor tooling in Xcode: https://stackoverflow.com/questions/33497338/how-do-i-refactor-swift-in-xcode – pkamb Oct 15 '20 at 19:36

2 Answers2

2

I would do this outside of Xcode with the help of some shell scripting. First, do a backup.

Then something like:

for f in `find . -name \*.storyboard -o -name \*.xib` ; do
cp $f $f.orig
sed 's/<button/<button customClass="MyButton" customModule="MyModule" customModuleProvider="target"/g' $f.orig > $f
done

Check if everything still works in Xcode (if not, you still have a backup in the .orig files)

Lastly you might also want to change some classes in your Code from UIButton to MyButton, but this cannot be automated since your code might reference some framework classes that sill will remain UIButtons.

Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34
0

Actually not pretty clear but note that if you looking for clean way to effect for all instances is using Type properties like static and class will be good idea

DrainOpener
  • 186
  • 1
  • 18