In my view-controller usually I load some data from server and call some function to render data or do some action when request data comes back from server. following is the snippet of such code.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
__weak typeof(self) weakSelf = self;
[MyRequestManager loadObjects: ^(MyObject* object, NSError* error) {
weakSelf.textField.text = object.text;
//do some other actions
}];
}
If before data comes from server view is disappeared/unloaded, will callback will be called? If it is called there are chances of crash of unexpected things to happen. So how can we prevent that from happening?
I can think of one way to set a variable in viewWillAppear and viewWillDisappear. What is recommended way of doing this?