john doe
john doe

Reputation: 9660

UIAlertController from Inside the AppDelegate

I am trying to present UIAlertController from inside AppDelegate and I am getting all sort of errors:

I have @import UIKit; at the top.

What am I doing wrong?

UPDATE: Here is the code:

  switch (accountStatus)
    case CKAccountStatusCouldNotDetermine:
    case CKAccountStatusNoAccount:
    case CKAccountStatusRestricted:

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert." preferredStyle:UIAlertControllerStyleAlert];

        break;

If I remove the UIAlertController line then everything is fine! The error just says Parse Issue, Expected Expression. thats it

Upvotes: 0

Views: 342

Answers (1)

Paul.s
Paul.s

Reputation: 38728

You can not create a local variable in a switch statement like that without introducing a new scope. Logical ORing the enumeration values together is also probably not what you want - you can instead have the cases fall through.

switch (accountStatus) {

  case CKAccountStatusCouldNotDetermine:
  case CKAccountStatusCouldNoAccount:
  case CKAccountStatusCouldRestricted: {
    UIAlertController *controller = 
      [UIAlertController alertControllerWithTitle:@"My Alert"
                                          message:@"This is an alert."
                                   preferredStyle:UIAlertControllerStyleAlert];
  } break;

}

You'll obviously need to have some kind of context to present this viewController but your code listing does not show enough to provide any further code

Upvotes: 3

Related Questions