Swift: default property and setting in initializer

Is there a drawback in quickly using the default property value instead of setting it in the initializer?

eg,

class Foo: UIViewController { let value = UIRefreshControl() } 

against.

 class Bar: UIViewController { var value : UIRefreshControl! // or using init() override func viewDidLoad() { self.value = UIRefreshControl() } } 

The default values ​​of the properties look more concise and elegant, but I do not see them in the code examples where they can be used.

+5
source share
1 answer

The only drawback is that default property values ​​are set each time an instance of an object is created, even if the property is subsequently overwritten by one or more initializers. This is probably not a problem if you just assign numerical values ​​by default, but if there is a class that is expensive, you can double the work.

+2
source

Source: https://habr.com/ru/post/1212885/


All Articles