Search code examples
iosobjective-cidentifierliteralsnon-ascii-characters

Non-ASCII characters are not allowed outside of literals and identifiers objective-c


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?


Solution

  • 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.