-3

I'm getting an error as 'Non-ASCII characters are not allowed outside of literals and identifiers'. Below is code :

- (void)purchaseMyProduct:(SKProduct *)product {

    if ([self canMakePurchases]) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    else{
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Purchases are disabled in your device" message:nil delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];

        [alertView show];
    }
}

Screenshot

I'm getting this error on else block. I have tried deleting empty spaces but didn't worked. Where am I going wrong?

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177

1 Answers1

6

Delete the line with the else on it (delete it completely, including the line break), then type it in again, manually, then clean and build again.

Xcode sometimes mishandles the way spaces are inserted when you copy and paste code from a rich-text source (e.g. a website), and unicode spaces are inserted instead of normal spaces, and these are not recognised by the compiler. Deleting the line completely and retyping it manually solves this problem as the offending characters are removed.

Greg
  • 9,068
  • 6
  • 49
  • 91
  • There is no "mishandling" here. When I copy text I expect it to be pasted in as it is, and that's what Xcode does. – gnasher729 May 19 '15 at 10:08
  • @gnasher729 I say "mishandling" because I have had instances where the spaces were in fact normal, non-Unicode spaces, and Xcode did this. If you disagree with my wording, feel free to edit. – Greg May 19 '15 at 10:09
  • @gnasher729 : Use of "mishandling" is appropriate in this context – Jayprakash Dubey May 19 '15 at 10:57