SwiftDeveloper SwiftDeveloper - 1 year ago 95
Swift Question

Swift Optional Value in variable

I have some variables all coming true just

output shows
. I didn't resolve it. I want to fix it to

My code below.

if let myString: String = String(seans.SeanceDate) {
let myStringArrf = myString.componentsSeparatedByString("T")
let tarih: NSString = myStringArrf[0]
let saat: String = String(myStringArrf[1])
let myStringArrf2 = saat.componentsSeparatedByString(":")
let saat1: String = myStringArrf2[0]
let saat2: String = myStringArrf2[1]

cell.saat.text = "\(saat1):\(saat2)"
cell.saat2.text = "\(saat1):\(saat2)"

let myStringArrf23 = tarih.componentsSeparatedByString("-")
let tarih1: NSString = myStringArrf23[0]
let tarih2: NSString = myStringArrf23[1]
let tarih3: NSString = myStringArrf23[2]

let sontarih: String = ("\(tarih3)-\(tarih2)-\(tarih1)")
cell.tarih.text = sontarih


Answer Source

You use optional binding to find out whether an optional contains a value, and if so, to make that value available as a temporary constant or variable. Optional binding can be used with if and while statements to check for a value inside an optional, and to extract that value into a constant or variable, as part of a single action

if let constantName = someOptional {
    // statements

if let tarih1 = myStringArrf23[0]{
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download