objective-cuiviewlazy-initializationaccessoryview

How to Initialise view as lazy var in Objective C


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


Solution

  • 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;
    }