最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Heap Memory Stair-Case rising in SwiftUI project - Stack Overflow

programmeradmin3浏览0评论

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 = ["
发布评论

评论列表(0)

  1. 暂无评论