ios - Swift: UIButton textLabel.text value not useable in switch statement -


i new swift , ios development, trying build calculator app learning purposes. however, encountering error. have titled of buttons number represent, retrieving title in buttonpress ibaction via sender.titlelabel.text. then, pass switch statement determine if button number or operator.

func handlebutton (sender:uibutton) { switch sender.titlelabel.text { case "1","2","3","4","5","6","7","8","9","0" :     println(sender.titlelabel.text) default:     break     }      } 

the error sender.titlelabel.text not bind string values have entered - nor string values - though of type string.

there seems bug in complier @ moment implicitly unwrapped optionals cannot used in switch statements. instead can use optional binding satisfy compiler. plus, handle case titlelabel.text nil.

func handlebutton (sender:uibutton) {     if let text = sender.titlelabel.text {         switch text {             case "1","2","3","4","5","6","7","8","9","0" :                 println(sender.titlelabel.text)             default:                 break         }     }     else {         // sender.titlelabel.text nil     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -