Question

Is it ok if i do something like:

  -(void)example{
       __weak __typeof__(self) weakSelf = self;

       dispatch_queue_t dispatchQueue = dispatch_queue_create("q_getRestaurants", NULL);
       dispatch_async(dispatchQueue, ^{

           dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf doSomething];
           });
       });
    }



   -(void)doSomething{
       //can i use self inside this method????
       self.view.backgroundColor = [UIColor redColor];
   }

The thing is that i wanna know if there is ok if i use self inside the do something method that is being called from a queue that has a weakSelf call.

Was it helpful?

Solution

Yes. You're good there. Only variables inside the block itself are retained.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top