Friends, tell me who knows - There is a custom class method that returns the NSData variable - responceData. It is initialized with a response from the server in the block code. The problem is that my method executes return and exits the method earlier than it enters the block with responds, thus returning nil.
What are the ways to solve this situation?
-(NSData *) getDataFromServer { __block NSData *responceData = nil; NSURLSessionConfiguration *sessionConfiguration= [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:[NSOperationQueue mainQueue]]; NSURL *url = [NSURL URLWithString:self.urlForResource]; NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { responceData = [[NSData alloc] initWithData:data]; }]; [dataTask resume]; return responceData; }