skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search