I have a modal view that comes up requiring the user to verify his/her email before continuing. This modal view can be presented from two different spots in the app. In one spot it comes from another modal view. This is my code for dismissing both modal views at once (works great).

```
MYUser *thisUser = [MyUser thisUser];
[thisUser refreshInBackgroundWithBlock:^(MyObject *thisUser, NSError *error) {
if (thisUser){
  if ([[thisUser objectForKey:@"emailVerified"] intValue]) {
    [self dismissViewControllerAnimated:YES completion:^{
      MyLoginViewController *controller = (MyLoginViewController *)self.presentingViewController;
      [controller verifiedEmail];
      }
    }];
  } else {
      NSLog(@"Not verified");
  }
} else {
    NSLog(@"%@", error);
  }
}];

```

The problem starts when I try to add a check incase it doesn't come from another modal view. I have tried inserting this if statement into my `dismissViewControllerAnimated:complete:^` block:

```
* if ([self.presentingViewController respondsToSelector:@selector(verifiedEmail)]){}
if ([self.presentingViewController isMemberOfClass:[MyLoginViewController class]]){}
* if ([self.presentingViewController class] == [MyLoginViewController class]){}

```

None of these work. They either fail (in the event of the \*'d ones) or crash the app. I'm thinking the issue is because `self.presentingViewController` isn't typecast, but if I `NSLog(@"%@", [self.presentingViewController class]);` and `NSLog(@"%@", [MyLoginViewController class]);`, the output looks identical.

Any ideas? Thanks.

**EDIT WITH SOLUTION**

It turns out that you cannot call `self.presentingViewController` inside the completion block because it is `null` at that point. I modified the code to this:

```
MYUser *thisUser = [MyUser thisUser];
id presentingVC = self.presentingViewController;
[thisUser refreshInBackgroundWithBlock:^(MyObject *thisUser, NSError *error) {
if (thisUser){
  if ([[thisUser objectForKey:@"emailVerified"] intValue]) {
    [self dismissViewControllerAnimated:YES completion:^{
    if ([presentingVC isMemberOfClass:[MyLoginViewController class]]){
      MyLoginViewController *controller = (MyLoginViewController *)presentingVC;
      [controller verifiedEmail];
      }
    }];
  } else {
      NSLog(@"Not verified");
  }
} else {
    NSLog(@"%@", error);
  }
}];

```

And it is now working wonderfully. Thanks for getting me pointed in the right direction!