我有一个文本视图供用户输入一个Int。将文本视图设置为Int而不是String? Swift
我遇到了将结果保存到Int变量的问题,因为它默认认为它是一个字符串。
什么是强制输出为Int的最佳解决方案?我使用的是数字只有键盘,使用户无法进入串
代码:
@IBOutlet weak var userExerciseWeight: UITextField!
var userExerciseWeightSet = Int()
if let userExerciseWeightSet = Int(self.userExerciseWeight.text!) {
}
您的测试代码在哪里? – Sachith
请阅读这些链接以改善您的问题:[Tour](http://stackoverflow.com/tour)| [如何问](http://stackoverflow.com/help/how-to-ask)| [最小,完整和可验证示例](http://stackoverflow.com/help/mcve) – Tom
更新了OP ... – infernouk