2

I have an app with:

  • custom topbar and bottombar,
  • horizontal scrollview that contains 5 other vertical scrollviews
  • the scrollviews are filled with a grid of images (no collection view)
  • a view that comes in from left when you grab it (google play store style)

So i have some views in there and i don't make use of interface builder.

If i launch my app on my iPhone 4s (not in debugging mode) my app takes almost 10 seconds to load, so my splash screen is up for 10 seconds.

Why does my app take so long to load up?

I tested it and it takes only 1.3 seconds to load all the images from the memory.

Is my app taking 8.7 seconds only to load my layout?

I wrote all the layout by code, with no use of constraints, i assign the frame sizes and positions for all the views in viewWillappear() method of the viewController.

How can i make it faster to load at start? where am i doing wrong? can it be layout's loading fault?

Thank you

Wain
  • 118,658
  • 15
  • 128
  • 151
simodev
  • 73
  • 2
  • 11
  • do you do anything with network that might take long? – luk2302 Jun 21 '15 at 10:12
  • Lash in a load of logging, find out what bits are taking time! – Woodstock Jun 21 '15 at 10:20
  • I don' t do anything network related – simodev Jun 21 '15 at 10:22
  • You should use instruments (you can run it using cmd+p form xcode, in the build menu it's called 'profile') and use the time profile to find your bottleneck. – Nils Ziehn Jun 21 '15 at 10:24
  • 1
    Use instruments and the time profiling tool, anything anyone says here is a random guess based on the zero information we have. You really should think seriously about why you aren't using storyboards and auto layout... – Wain Jun 21 '15 at 10:33
  • Ok, thank you, i'll try the time profiling tool, i got tired of storyboards because in my opinion with frames it's faster to make complex layouts, thank you for the advice, i am still learning – simodev Jun 21 '15 at 10:53

1 Answers1

2

Instruments revealed that my error was in assigning a font that i removed from the resources to a UILabel with the method

    button.titleLabel?.font = UIFont(descriptor: UIFontDescriptor(name: "MyFont", size: 21), size: 21)

this line was the problem, it was spending a lot of time looking for the font that was not there.

so i replaced that line with:

    UIFont.systemFontOfSize(21)

Hope this helps someone

simodev
  • 73
  • 2
  • 11
  • how can i check ,where my app taking a long time, I have just added fonts – Varinder Singh iPhone Dev Sep 15 '16 at 14:04
  • @SimonePauro. Can u guide how to test with instruments because my app takes long time to launch the app. – Uma Madhavi Feb 10 '17 at 12:39
  • Hi @UmaMadhavi, I followed [this tutorial](https://www.raywenderlich.com/97886/instruments-tutorial-with-swift-getting-started), it's very easy to understand – simodev Feb 12 '17 at 15:04
  • @SimonePauro. I have seen the tutorial , but i am not understanding how to open Xcode from there . Please guide me. – Uma Madhavi Feb 13 '17 at 04:57
  • To open the time profiler instrument you should: - open your Xcode project - on the top menu Product -> Build for -> Profiling (attached [image](https://drive.google.com/open?id=0B4lPiuh9bccnaFI1Uk8tS0M3SlU)) - the instruments window will open up - select the time profiling instrument and you are ready to go – simodev Feb 13 '17 at 16:13
  • @SimonePauro.. How can i know that time consumed much in each thread & where it is happening . – Uma Madhavi Feb 14 '17 at 04:55