ios - How can i get the data from Swift based IBOutlet UITextField? -


 @iboutlet  var firstname:uitextfield?  @iboutlet  var lastname:uitextfield?   let string = firstname!.text  print(string) 

the output below:

optional("ohh")

how can data without optional text , double quotes?

your issue text attribute of uitextfield optional - means must unwrapped. that, add ! end, produces string instead of string?.

you can conditionally unwrap optional using syntax if let, here be

if let string = firstname!.text{ print(string) //outputs if text exists }else{ //text didn't exist } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -