0

When creating a singleton object of a UIView inside the view class, I use the static keyword.

class AView: UIView {

static let shared = AView()

}

Now in my UIViewController class, instead of using "AView.shared" to access that singleton object, I create a constant reference inside the View Controller.

class AViewController: UIViewController {

let singleton = AView.shared

// now I use singleton.whatever to access the view properties and methods.

}

Question 1: Am I creating a second object by creating "let singleton = AView.shared"? I am NOT trying to create a second object because that's redundant and I'm sure could lead to memory leaks somehow, right? The goal is for me to just create a reference inside that ViewController class for readability.

Question 2: Is this good convention?

0 Answers0