Xcode can only refactor C and Objective-C code. How to rename swift class name in Xcode 6?

后端 未结 6 1869
遥遥无期
遥遥无期 2020-12-24 11:28

I have created a new Single View Application Project in Xcode 6 beta version. I want to rename swift class from ViewController.swift to some other name. But whe

6条回答
  •  难免孤独
    2020-12-24 12:02

    From this tutorial.

    Split up your iOS8 Swift Code

    First things first, let’s rename our View Controller to be something more meaningful. Open up your ViewController.swift file and replace all references to ‘ViewController’ with our new name, ‘SearchResultsViewController’. Rename the file as well to SearchResultsViewController.swift.

    If you try to run the app from here you’ll get a crash. This is because our storyboard file hasn’t been updated to know about the new class! So open up the Main.storyboard, select your ‘View Controller’ object in the scene (the left-hand side nav), and then select the Identity Inspector (right-hand side, third button.)

    From here let’s change the class from ‘ViewController’ to ‘SearchResultsViewController’. Now we should be back on track. Check that the project still works, and let’s proceed.

提交回复
热议问题