I think what you're asking is how to implement something similar to the following:
@property (nonatomic, strong) UIView *topView
- (UIView *)topView {
if (_topView == nil) {
_topView = //...
// configure _topView...
}
return _topView;
}
This lazy property getter is easy to achieve in Swift:
lazy var topView: UIView = {
let view = //...
// configure view...
return view
}()
This results in a read-only variable that is initialised only when first accessed. The Swift code you posted is a computed read-only property which is evaluated every time it is accessed.