Parse issue, Expected ')'

I have been trying to get rid of many errors, and this one still persists:


if ([localeClass respondsToSelector:localeSelector]) {

IMP getLocaleIMP = [localeClass methodForSelector:localeSelector];

NSString *(*getLocale)(id, SEL) = (void *)getLocaleIMP;

NSString *fcmLocale = getLocale(localeClass, localeSelector);

if (fcmLocale != nil) {

return fcmLocale;

}

}


NSString *systemLanguage = [[NSLocale preferredLanguages] firstObject];

if (systemLanguage != nil) {

return systemLanguage;

}


int iOS;

int available;


if (available(iOS 10.0, *)) { (ISSUE expected ')')

return [NSLocale currentLocale].languageCode;

} else {

return nil;

}

}



No matter where I look, I cannot find where to put the ')'. This is forbidding me to run the app, which is quite inconvenient. On the side, it says:

Parse Issue

Expected ')'

! To match '('


Please help!

Replies

I think junkpile has answered your direct question, but I’d like to ask a follow-up. You wrote:

if ([localeClass respondsToSelector:localeSelector]) {
  IMP getLocaleIMP = [localeClass methodForSelector:localeSelector];
  NSString *(*getLocale)(id, SEL) = (void *)getLocaleIMP;
  NSString *fcmLocale = getLocale(localeClass, localeSelector);
  if (fcmLocale != nil) {
      return fcmLocale;
  }
}

What are you trying to do with the above code? It looks like you’re testing to see whether a class implements a selector and, if it does, calling that selector. If so, you can’t need to mess around with low-level Objective-C runtime calls. Instead, you write code like this:

NSLocale * locale = NSLocale.currentLocale;
if ([locale respondsToSelector:@selector(languageCode)]) {
    return [locale languageCode];
}

[I’m using the

languageCode
getter as an example here; it wasn’t clear from your post which selector you’re concerned above.]

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The noted ')' error is fallout, and apparently not the real error?


int available;
  
    if (available(iOS 10.0, *)) {                                                  (ISSUE expected ')')
      
   return [NSLocale currentLocale].languageCode;
  } else {
    return nil;
  }
} <---?



The bracket count in that snippet is odd...should be even. You seem to have an unmatched/dangling/extraneous '}' ?