.I am new to iOS and to Swift In my application I'm trying to print an optional value and it prints "Optional(value of the variable)" How do I remove this word optional
var bDay = StringUtils.convertDateToString(birthDate, format: Constants.BIRTHDAY_FORMAT)
let age = self.clientDetail?.getAge()
println("age.....\(age)")
bDay += "\(age)"
The output in the console is
age.....Optional(29)
I'm trying to assign this variable to a UILabel but on screen it shows up like Sep 17, 1986 Optional(29)
My objective is to remove this optional word and make it appear like Sep 17, 1986(29)
Thanks in advance
Optional chaining is used here:
let age = self.clientDetail?.getAge()
So return of getAge()
is optional value. Try optional binding:
if let age = age {
println("age.....\(age)")
}
or simply unwrap the age
with age!
, but this will crash your app if age
is nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With