Search code examples
iosswiftperformancesnapkit

iOS SnapKit performance on presented view


Issue Description

I'm creating a new view and have the constrains of all the UI elements on a function that is called on the viewDidLoad function.

The view is presented via the following code, the time it takes to show the view the fist time is over 5-6 seconds which is quite a lot.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("newView") as! NewView
self.presentViewController(controller, animated: true, completion: nil)

The constrain declarations are approximately over 20 mostly UILabel, UIButton, UIView elements.

Is there a way to speed the first load of the presented view? Or is there a better way or place to declare constrains with SnapKit?

Note: I'm using purely Swift 2.2


Solution

  • It turns out that when using the creation on viewWillAppear or viewDidAppear rather than viewDidLoad the loading is faster.