-1

I am very new to swift. I have a class A, with many variables( can be static if required) as follows.

class A
{ 
    let a1 = "hello"
    let a2 = try! NSRegularExpression(pattern: #"https://.*"#, options: .caseInsensitive)
    func print()
    {
        // do something
    }
}

The object of class A is created many times as when required. But I want a1, a2 variables to be initialised only once and not every time an object of the class is created.

Thoughts:

  1. Does moving these variables outside the class and making them static, initialise them only once?
  2. Or should I make them lazy properties?

0 Answers0