0

I'm currently developing a custom keyboard app and am having trouble parsing what the keyboard has outputted onto the text document proxy. How does one go about this? I feel like I'm losing my mind. Currently I'm looping:

for letter in (proxy.documentContextBeforeInput?.characters)!

However, this is only getting the text on the line the cursor is currently on, before the cursor, such that if my textDocumentProxy contains:

Some text above

Some text below (cursor position)

My loop only iterates throught the "Some text below" portion.

Is there any way to loop through the entirety of a UITextDocumentProxy? Thank you.

1 Answer 1

-1

documentContextBeforeInput, as its name mentions, only returns the text before the input. To get the full text string, you should do something like:

let entireText = (proxy.documentContextBeforeInput ?? "") + (proxy.documentContextAfterInput ?? "")

if let chars = entireText.characters {
    for letter in chars {
        //DO something useful
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.