0

I have noticed that it is possible (in Xcode 12, at least) to do:

import UIKit.ViewController

class ViewController: UIViewController {}

Up until now I have always done import UIKit.

Does someone know which benefits one has from importing only the class? Does the app build/compile faster?

Thanks

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
  • 4
    [This might be helpful](https://nshipster.com/import/#clarifying-and-minimizing-scope). – Sweeper Sep 22 '20 at 12:43
  • 1
    Thanks @Sweeper, quite disappointing that it is only helpful "to clarify your intent as a programmer". I had hoped improved building times. – regina_fallangi Sep 22 '20 at 12:46
  • @regina_fallangi Just to note, it's not Xcode12 feature, this has been available since ever. Yes, no build time optimizations but it really improves code readability as said in the link – Ratz Oct 24 '20 at 09:50
  • 1
    @Ratz that’s a subjective matter, I’d say. Yes, it improves readability if you only need top 3-5 views. The moment you import more than 5 things, it starts to represent clutter. One can quickly end up with Java-like files where one has headers that can be 20-30 lines of code until one sees logic :) – regina_fallangi Oct 24 '20 at 10:38
  • 1
    @regina_fallangi Yes completely agree. It's depends on usage and the component. – Ratz Oct 26 '20 at 11:55

0 Answers0