How to Initialise view as lazy var in Objective C

257 Views Asked by At

Well! I had worked with Lazy var in swift. Nevertheless, I want to use the lazy var type to my accessory view in one of my Objective C projects. I couldn’t find the exact answer for declaring UIView as lazy var type. So, Share your ideas, if you had faced in anywhere the same. And I tried with below link already,



Reference Link

1

There are 1 best solutions below

1
ssowri1 On BEST ANSWER

Use the below code snippet, To get rid of such that issue.

   UIView *accesView = [[UIview alloc]init];
-(UIView *) inputAccessoryView {
    if (_accesView == nil) {
        _accesView = [[UIView alloc]init];
        inputView *view = [[[NSBundle mainBundle] loadNibNamed:@"inputView" owner:nil options:nil] firstObject];
        _accesView = view;
    }
    return _accesView;
}