我不小心在我的 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 。
只需在“查找”导航器中搜索名称即可。
您可以看到第二个结果是 Storyboard中的引用。您可以通过单击每个结果并按替换来逐一替换,或者如果您确定没有破坏任何内容,则可以直接全部替换。
关于ios - 在 Swift 中重命名 socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28150826/