我有四个文本字段。一个是完整的浴室,另一个是四分之三的浴室,另一个是半浴室,最后一个是四分之一浴室。但是在我转换为int之后,我仍然得到“无法转换int类型的值”的错误。这是代码。
HomeSingleton.sharedInstance3.HomeNumberOfFullBathstext = Int(Double(FullBaths.text!)! * 1.0) + Int(Double(Three_FourthsBaths.text!)! * 0.75) + Int(Double(One_HalfBaths.text!)! * 0.5) + Int(Double(One_fourthBaths.text!)! * 0.25)
答案 0 :(得分:2)
错误消息显示所有内容。您需要为其分配字符串值
HomeNumberOfFullBathstext
HomeSingleton.sharedInstance3.HomeNumberOfFullBathstext = String(Int(Double(FullBaths.text!)! * 1.0) + Int(Double(Three_FourthsBaths.text!)! * 0.75) + Int(Double(One_HalfBaths.text!)! * 0.5) + Int(Double(One_fourthBaths.text!)! * 0.25))
答案 1 :(得分:1)
也许使用:
HomeSingleton.sharedInstance3.HomeNumberOfFullBathstext = String(Int(Double(FullBaths.text!)! * 1.0) + Int(Double(Three_FourthsBaths.text!)! * 0.75) + Int(Double(One_HalfBaths.text!)! * 0.5) + Int(Double(One_fourthBaths.text!)! * 0.25))