How do I refactor Swift in Xcode?

后端 未结 4 1189
忘了有多久
忘了有多久 2020-12-13 23:26

Is there a way to refactor swift in Xcode 7.1?

When I try to rename a variable (e.g. highlight, right-click, refactor > rename), Xcode pops up an error dialog sayi

相关标签:
4条回答
  • 2020-12-14 00:06

    AFAIK the refactoring is not working with Swift right now, however, at least in the same file(scope), you can do the following:

    0 讨论(0)
  • 2020-12-14 00:09

    The lack of refactoring is astounding (especially as I am coming off of a major stint using VS) However I have just noticed that someone has done something about it. On GitHub there is Refactorator Xcode Plugin (MIT license) which claims:

    Refactorator is an Xcode plugin for refactoring Swift & now Objective-C code. It will rename public or internal vars, functions, enums etc. For private and local entities use Xcode's existing "Edit All in Scope" functionality.

    Full disclosure is that I have nothing to do with them and am just about to install the product myself.

    0 讨论(0)
  • 2020-12-14 00:11

    Xcode 9 - 10

    Xcode 9 now supports refactoring in Swift. This was announced in WWDC 2017.

    0 讨论(0)
  • 2020-12-14 00:30

    As of Xcode 7.2 beta the refactoring tools do not support Swift.

    What I do is use the type checker. Change the name/type of something and then fix all the compile breakages. Because of the strong typing you can have more confidence that this approach will catch everything. I have at times deliberately changed things and broken them temporarily to check where objects or types are used or accessed from.

    Or use AppCode for the refactoring, I hear it is good but haven't tried much myself.

    0 讨论(0)
提交回复
热议问题