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
Post a Comment