显示 swift 中的 bool 值
display the value of bool in swift
我想打印布尔值的结果
当我这样做时,我有 "true" 而不是金额。
我知道这听起来可能真的很愚蠢,但我才刚刚开始使用 swift
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
let months5weeks:Bool = true
let months4weeks:Bool = true
if months5weeks {
normalpay = hoursWageHours * months5WeeksHours
if months4weeks {
normalpay = hoursWageHours * months4WeeksHours
}
}
或者即使没有打印结果也会更有意义
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
if monthsWeek == 195 {
normalpay = hoursWageHours * months5WeeksHours
if monthsWeek == 4 {
normalpay = hoursWageHours * months4WeeksHours
}
}
月周 = 4
布尔变量只能取 2 个值(真或假)。
所以当你打印它时你有真或假是合乎逻辑的。
我来这里是为了寻找布尔值的实际打印。事实证明你可以这样做:
var a_bool = false
print("a_bool is ")
println(a_bool)
你可以用整数来做到这一点:
var a_int = 42
println("This is an int " + String(a_int))
但是你不能用 bool 来做到这一点。但是你可以这样做:
println("This is a bool " + String(stringInterpolationSegment: a_bool))
这是我能想出的衣柜:
println("a_bool is ", a_bool) // does not work
println("a_bool is " + a_bool) // also does not work
后来,我了解到您可以像这样使用 \(variable) 嵌入:
println("This is an int \(a_int)")
我想打印布尔值的结果 当我这样做时,我有 "true" 而不是金额。 我知道这听起来可能真的很愚蠢,但我才刚刚开始使用 swift
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
let months5weeks:Bool = true
let months4weeks:Bool = true
if months5weeks {
normalpay = hoursWageHours * months5WeeksHours
if months4weeks {
normalpay = hoursWageHours * months4WeeksHours
}
}
或者即使没有打印结果也会更有意义
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
if monthsWeek == 195 {
normalpay = hoursWageHours * months5WeeksHours
if monthsWeek == 4 {
normalpay = hoursWageHours * months4WeeksHours
}
}
月周 = 4
布尔变量只能取 2 个值(真或假)。 所以当你打印它时你有真或假是合乎逻辑的。
我来这里是为了寻找布尔值的实际打印。事实证明你可以这样做:
var a_bool = false
print("a_bool is ")
println(a_bool)
你可以用整数来做到这一点:
var a_int = 42
println("This is an int " + String(a_int))
但是你不能用 bool 来做到这一点。但是你可以这样做:
println("This is a bool " + String(stringInterpolationSegment: a_bool))
这是我能想出的衣柜:
println("a_bool is ", a_bool) // does not work
println("a_bool is " + a_bool) // also does not work
后来,我了解到您可以像这样使用 \(variable) 嵌入:
println("This is an int \(a_int)")