ios - 在 Swift 中重命名 socket

标签 ios xcode swift

我不小心在我的 View Controller 中拼错了其中一个导出并遇到了一些问题。当我手动尝试更正拼写错误时,我在运行时在 AppDelegate 中停止,我看到了消息,

Thread 1: signal SIGABRT

突出显示代码块的开头:

class AppDelegate: UIResponder, UIApplicationDelegate {
  ...
}

我发现要在 Objective-C 中解决此问题,您需要右键单击 socket 的原始名称和“Refactor => Rename”,但不幸的是我收到消息:

Xcode can only refactor C and Objective-C code

View Controller

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var billTextField: UITextField!

    @IBOutlet weak var tipRateSegmentedControl: UISegmentedControl!

    @IBOutlet weak var tiLabel: UILabel! // Variable name should be "tipLabel"

    @IBAction func calculateTapped(sender: AnyObject) {
        var userInput = billTextField.text as NSString
        var totalBill: Float = userInput.floatValue
        var index: Int = tipRateSegmentedControl.selectedSegmentIndex
        var tipRate: Float = 0.15

        if index == 0 {
            tipRate == 0.15
        } else if index == 1 {
            tipRate = 0.20
        } else {
            tipRate = 0.25
        }

        var tip: Float = totalBill * tipRate

        tipLabel.text = "$\(tip)"
    }
}

最佳答案

编辑:从 Xcode9 开始,有一个重构函数;新的好方法是一个in this answer


从 Xcode 6 开始,您可以直接在查找导航器 (Cmd+3) 中查找 socket 名称,它会显示您的代码以及您的 xib 和 Storyboard中的事件。它还适用于 Action 。

只需在“查找”导航器中搜索名称即可。

enter image description here

您可以看到第二个结果是 Storyboard中的引用。您可以通过单击每个结果并按替换来逐一替换,或者如果您确定没有破坏任何内容,则可以直接全部替换

关于ios - 在 Swift 中重命名 socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28150826/

相关文章:

iOS : Region monitoring and battery usage

ios - 引用 socket 未显示在 xcode 6 中

ios - 如何正确引用/检索在 AppData 中创建的临时文件以将文件上传到服务器?

c++ - 如何在不在 .h 文件中制作原型(prototype)的情况下将 Objective-C++ 类公开给 swift

ios - 我的 Firebase 数据库中的数据未加载到我的 TableView 中

ios - 无法在 XCODE 6 上获取 View 的宽度和高度

ios - Realm 主键迁移

ios - 我应该共享我的 trigger.io 配置文件和证书吗?

ios - 返回到另一个 Storyboard的按钮

swift - 我怎样才能更正这段代码,同时让它更简单