I have the following simple, fresh, single-view project in Xcode 10 with Swift 4.2
I introduced a typo in the string interpolation of the first string, but the compiler does not complain and the code runs.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let number: Int = 50
var string = "\(number.numberString, withValue: false) lbs"
print(string)
string = "\(number.numberString(withValue: false)) lbs"
print(string)
}
}
extension Int {
func numberString(withValue value: Bool) -> String {
if value == true {
return "value"
} else {
return String(self)
}
}
}
the printout is:
((Function), withValue: false) lbs
50 lbs
It is taking the first parameter as "(Function)", and reporting the rest of text inside the parenthesis as part of the text, but the editor doesn't show it as a text. Is there something I don't understand in the string interpolation syntax? or is this a complier issue/bug?
Thx
It's displaying exactly what you're requesting. You're evaluating:
(number.numberString, withValue: false)
This is a tuple with an unlabeled function value and a labeled boolean value. The description of that tuple would be:
((Function), withValue: false)