Problem in receiving the return of an object

1

I created a class to download data from a web service. And I take the following steps to test:

Instantiate the download class in viewDidLoad of ViewController and then execute the method, as in the code below:

    - (void)viewDidLoad {
        [super viewDidLoad];
        GDRequestURL* getData = [[GDRequestURL alloc]init];
        [getData getDataFromURL];
        // Aqui instancio um objeto para receber o retorno.
        NSMutableArray* restultado = [[NSMutableArray alloc]init];

        //NEste ponto faço a execução para receber o retorno dos dados.
        restultado = [getData retornaResultado];
  }

But the return is nil.

    
asked by anonymous 24.01.2015 / 21:31

1 answer

1

I was able to solve it !! The problem was at the time I was performing the data return for the variable result. I was doing this before getData perform the data request. So I created a global variable of the GDRequestURL class in ViewContronller, and created an action button to be used for testing, and perform the action of returning the data after the completion of the request. Staying like this:

ViewController.h

...

@interface ViewController{

GDRequestURL* getData;

}

ViewController.m

    ...
     - (void)viewDidLoad {
            [super viewDidLoad];


            getData = [[GDRequestURL alloc]init];
            [getData getDataFromURL];

      }

...

-(IBAction)retornaValores{

         // Aqui instancio um objeto para receber o retorno.
            NSMutableArray* restultado = [[NSMutableArray alloc]init];

            //NEste ponto faço a execução para receber o retorno dos dados.
            restultado = [getData retornaResultado];

...

}
    
31.01.2015 / 22:54