A simple keyboard extension app showing continuous heap memory allocation each time open the keyboard on screen.
For easier understanding see the image below...
Here is the KeyboardViewController:
class KeyboardViewController: UIInputViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myController = UIHostingController(
rootView: AnimalKeyboardView(
insertText: { [weak self] text in
guard let self else { return }
self.textDocumentProxy.insertText(text)
}
))
let animalKeyboardView = myController.view!
animalKeyboardView.translatesAutoresizingMaskIntoConstraints = false
self.addChild(myController)
self.view.addSubview(animalKeyboardView)
myController.didMove(toParent: self)
NSLayoutConstraint.activate([
animalKeyboardView.leftAnchor.constraint(equalTo: view.leftAnchor),
animalKeyboardView.topAnchor.constraint(equalTo: view.topAnchor),
animalKeyboardView.rightAnchor.constraint(equalTo: view.rightAnchor),
animalKeyboardView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
}
And AnimalKeyboardView:
struct AnimalKeyboardView: View {
var insertText: (String) -> Void
private let animalList = ["