Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove first character from textfield value in swift

if my textfield takes 11 characters then i need to remove first character and then pass it to jason perameter, so i tried like below

var dropFirst: String?
if emailPhoneTextField.text?.count == 11{
    dropFirst = emailPhoneTextField.text?.dropFirst()
        emailPhoneTextField.text = dropFirst 
    }

then o/p: then error, how to fix

Cannot assign value of type ‘String.SubSequence?’ (aka ‘Optional’) to type ‘String?’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

dropFirst returns SubSequence so you can’t assign it directly to textfield’s text property that accepts an optional string (String?) , So replace

dropFirst = emailPhoneTextField.text?.dropFirst()

With

dropFirst = String(emailPhoneTextField.text!.dropFirst())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading