ios - Swift get textbox value surounded by optional() -


my viewcontroller

/ mark: properties @iboutlet weak var textinput: uitextfield!  @iboutlet weak var labeltop: uilabel!  override func viewdidload() {     super.viewdidload()             textinput.delegate = self }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: uitextfielddelegate func textfieldshouldreturn(textfield: uitextfield) -> bool {     textfield.resignfirstresponder()     return true }  func textfielddidendediting(textfield: uitextfield) {     if (textinput != nil){         labeltop.text = "searching \(textfield.text)"         textinput.enabled = false     }                            } 

when press return on textfield code

labeltop.text = "searching \(textfield.text)" 

is called. text of labeltop looks like:

searching optional("the text")

i looked @ optionals (most times use ? instead of ! right?) not understand how should value without surrounding 'optional("")'

you need unwrap optional value.

if let text = textinput?.text {     labeltop.text = text     textinput.enabled = false }     

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -