Aleksandr Shcherbakov
Aleksandr Shcherbakov

Reputation: 768

Nib files loading extremly slow

Good day friends!

I have very strange performance results on loading Nib files. Here is a screen from TimeProfiler:

enter image description here

Overall it sometimes takes more than 1200 ms to load a simple viewController that has 2 nibs. Nibs are very simple. Here is an example. As you can see from screenshot above, it takes 311 ms to be loaded:

enter image description here

The code I use to load nibs:

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    setupXib()
}

func setupXib() {
    NSBundle.mainBundle().loadNibNamed("TimeSaver", owner: self, options: nil)
    bounds = view.bounds
    addSubview(view)
    setup()
}

func setup() {
    slider.maximumValue = 30.0
    slider.minimumValue = 1.0
    slider.value = 5.0
    timeLabel.text = "\(sliderValue.format(format)) min"
}

I don't know if it might cause a problem, but this app uses App Groups (for WatchExtension). As you see I call nibs from mainBundle as they all are in main target. May it be the reason?

Thank you!

Upvotes: 6

Views: 1414

Answers (1)

Aleksandr Shcherbakov
Aleksandr Shcherbakov

Reputation: 768

So the problem was not in nib files at all. It was about custom font that was not installed properly. It was in list in Storyboard, but it was not a member of correct target. So the app was looking through everywhere to find a damn font - and that was the performance issue.

Upvotes: 12

Related Questions