Dispatch_queue issue
===

I'm new using <code>dispatch_queue_t</code> and I have two problems with my app which I think that could be solved using GCD. The first one is that in the main view (ViewController) I have a label which is actualized by another class (AudioViewController), and when I do any user interaction in ViewController the label stop to actualize, so I think if I use <code>dispatch_queue_t</code> this problem will be solved.

The second thing is that in the same main view (ViewController) when I press a contribution I call another class (ContributionViewController) and this class accesses just a instance variable of another class (AudioViewController) which is refreshed all the time. When I start contribution, I made a loop to get more than one value to make some calculus with them and those values are all the same though.

I'll put some code here trying to clear the things.

<code>ViewController.m</code>
     
    - (IBAction)makeContribution:(id)sender
    {
      NSLog(@"A: Contribution button clicked");
      NSLog(@"-= START CONTRIBUTION =-");
      cvc = [[ContributionViewController alloc] init];
      cvc.avc = self.avc;
    
      // Get NUM_CONTRIBUTIONS contributions to make average.
      int contContribution;
      for (contContribution = 0; contContribution < NUM_CONTRIBUTIONS; contContribution++) {
            [cvc getEachContribution];
      }
    
      // Make average
      [cvc makeAverage:NUM_CONTRIBUTIONS];
    
      [cvc release];
    }

<code>AudioViewController.m</code>

    - (void)audioInitializationWithTimeInterval:(float)time
    {
       NSDictionary* recorderSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
                                      [NSNumber numberWithInt:44100],AVSampleRateKey,
                                      [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
                                      [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
                                      [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
                                      [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
                                      nil];
       NSError* error;
    
       NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
       recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recorderSettings error:&error];
    
       //enable measuring
       //tell the recorder to start recording:
       [recorder record];
    
       if (recorder) {
          [recorder prepareToRecord];
          recorder.meteringEnabled = YES;
          [recorder record];

          levelTimer = [NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(levelTimerCallback:) userInfo:nil repeats:YES];
       }
       else
          NSLog(@"%@",[error description]);
    }


    - (void)levelTimerCallback:(NSTimer *)timer
    {

       //NSLog(@"-= AVC =-");
       [recorder updateMeters];
    
       db = [recorder averagePowerForChannel:0] - DBOFFSET;
       db += 120;
       db = db < 0 ? 0 : db;
    
       vc.lab_decibel.text = [NSString stringWithFormat:@"%0.0f", db];
    }

<code>ContributionViewController.m</code>

    - (void)getEachContribution
    {
      actualContribution = self.avc.db;
      NSLog(@"Actual contribution: %f", actualContribution);
      NSLog(@"Sum before: %0.2f", sumContribution);
      sumContribution += actualContribution;
      NSLog(@"Sum After: %0.2f", sumContribution);
    }


    - (void)makeAverage:(int)numOfContributions
    {
      self.average = self.sumContribution / numOfContributions;
      NSLog(@"Average: %0.2f", self.average);
    }

So, the main thing is <code>dispatch_queue_t</code> is going to solve my problems and how to do that? I've tried to put <code>dispatch_queue_t</code> on AudioViewController, ContributionViewController and ViewController, but the first didn't update the label, the second crashed and the third one the label still with 0 value.

Thanks for any tips to solve this problem.
