9

When I was truing to rename my class in swift it will show error like below.

Rename Class or Attribute

Swift-Refacoring

I just want to know that, in Objective C it allow us to rename class name, then why it not available in Swift, or any other way to do the same.

If there is any good way then please suggest me.

Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
VRAwesome
  • 4,721
  • 5
  • 27
  • 52
  • 1
    Swift is a new language and the IDE needs time to mature. I wish Apple focus more on the tools than keep changing the language syntax. There is limited capability to rename classes and variables. See [this question](http://stackoverflow.com/questions/33497338/how-do-i-refactor-swift-in-xcode) – Code Different Jul 15 '16 at 13:42
  • Xcode 9 promises the refactoring of Swift. https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/WhatsNewXcode/xcode_9/xcode_9.html#//apple_ref/doc/uid/TP40004626-CH8-SW2 – Shad Jun 07 '17 at 03:53

1 Answers1

12

At present Xcode doesn't support cross-file refactoring

It can rename a method, function, variable... but only within the same file though.

To do it

  1. Put the cursor on the member you want to rename
  2. press ctrl + cmd + e
  3. change the member
  4. all the references within the same file will be updated in realtime

But it doesn't updated references from other files. For this we need to wait for a future version of Xcode.

Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148