Why no need of parenthesis to access nested class?

Code Block
class One {
  func sayOne() {
    print("from inside One")
  }
   
  class Second {
    func saySecond() {
      print("from inside second")
    }
  }
}
One.Second().saySecond()

Why can I access Second class without instantiating One() with parenthesis, when I can't access member function and variables without instantiation with ()?
Answered by Claude31 in 669047022
You have defined Second inside One.

So, when you call One.Second(), you just create an instance of Second ("prefixed" by One). You don't have to create an instance of One.
You do the same when you call from a framework:
Code Block
          let vc = UIKit.UIViewController()

which is equivalent to
Code Block
          let vc2 = UIViewController()

One just tells that we look for Second() inside this class.


Accepted Answer
You have defined Second inside One.

So, when you call One.Second(), you just create an instance of Second ("prefixed" by One). You don't have to create an instance of One.
You do the same when you call from a framework:
Code Block
          let vc = UIKit.UIViewController()

which is equivalent to
Code Block
          let vc2 = UIViewController()

One just tells that we look for Second() inside this class.


Good example with UIKit! Helps sink that in.
Why no need of parenthesis to access nested class?
 
 
Q