Calling UITextView() takes 5.8 second in keyboard extension with Swift 2?

痴心易碎 提交于 2019-12-13 03:37:54

问题


I just updated my XCode form 6.3 to 7.1 and thus also my project from Swift 1.2 to Swift 2.

Everyting seems to work except my app starts some 6 seconds slower then it used to.

I tracked the problem to this class initializer:

class TextPreviewAdapter {
    private let themeProvider: ThemeProvider
    private let containerView: UIView
    private let previewText: UITextView
    private let carretView: UIView

    private var carretTextPosition: UITextPosition?

    init(themeProvider: ThemeProvider) {
        self.themeProvider = themeProvider
        containerView = UIView()
        let time = CACurrentMediaTime()
        previewText = UITextView()
        print("TextPreviewAdapter \(CACurrentMediaTime() - time)")
        carretView = UIView()
    }

    //some unimportant code
}

The output of the print call is

TextPreviewAdapter 5.86848595833144

The time is different every time I run the up from XCode.

The app is keyboard extension. This might not be the only performance problem introduced by the migration. The whole app appear slugish, in particual rotation animations are slow, somethimes a fast swipe is not handled... Nothing of that was present before migration.

On output I have some suspicious logs (also not present before migration):

2015-10-23 00:39:55.591 ProductName Keyboard[3293:300203] _BSMachError: (os/kern) invalid capability (20)
2015-10-23 00:39:55.592 ProductName Keyboard[3293:300203] _BSMachError: (os/kern) invalid name (15)
2015-10-23 00:39:55.593 ProductName Keyboard[3293:300203] _BSMachError: (os/kern) invalid capability (20)
2015-10-23 00:39:55.593 ProductName Keyboard[3293:300203] _BSMachError: (os/kern) invalid name (15)
2015-10-23 00:45:02.532 ProductName Keyboard[3293:300964] host connection <NSXPCConnection: 0x147e459c0> connection from pid 3292 invalidated

Anybody had the same problem? Any ideas on how to solve this issues?

来源:https://stackoverflow.com/questions/33292099/calling-uitextview-takes-5-8-second-in-keyboard-extension-with-swift-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!