dimanche 7 juin 2020

is it possible to PRESS ENTER programmatically in swift?

I am making typing game in swift. but there are some problem. first of all this is my code.

if let input = textField.text{
 //비교를 위한 글자 분해한 배열
            let whatYouHaveToWrite = Text.init().textArray[a]
            let whatYouAlreadyWrite = input

            let attr = NSMutableAttributedString(string: viewLabel.text!)

            for i in 0...Array(whatYouHaveToWrite).count-1{

                    //한글자 맞았는지 인식하는 것
                if i <= Array(whatYouAlreadyWrite).count-1{
                    if Array(String(whatYouAlreadyWrite))[i] == Array(whatYouHaveToWrite)[i]{
                        attr.addAttribute(.foregroundColor, value: UIColor.systemBlue, range: NSRange(location:i,length:1))
                        ENTER()
                    }

                    //한글자 틀렸는지 인식하는 것
                    if i>0 {
                        if Array(String(whatYouAlreadyWrite))[i-1] != Array(whatYouHaveToWrite)[i-1]{
                            attr.addAttribute(.foregroundColor, value: UIColor.systemRed, range: NSRange(location:i-1,length:1))
                        }
                    }
                } else{ break }
            }
}

for example when you are typing "사랑" process is like this. "ㅅ" -> "사" -> "살" -> "사랑" and if I type "사" as you can see in my code "사"'s color are changed to blue. but problem is when you type "살" in order to type "사랑". So when I type "사" I want to PRESS ENTER programmatically in "if Array(String(whatYouAlreadyWrite))[i] == Array(whatYouHaveToWrite)[I]" and there are some method that trigger press enter programmatically?

Aucun commentaire:

Enregistrer un commentaire