6 Replies
      Latest reply on Jun 7, 2019 5:57 PM by Bri Ho
      Bri Ho Level 1 Level 1 (0 points)

        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!

        • Re: Parse issue, Expected ')'
          eskimo Apple Staff Apple Staff (12,475 points)

          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"

          • Re: Parse issue, Expected ')'
            KMT Level 9 Level 9 (15,305 points)

            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 '}' ?

              • Re: Parse issue, Expected ')'
                Bri Ho Level 1 Level 1 (0 points)

                I don't have the ')' problem anymore, and @junkpile, I made:

                 

                if (@available(iOS 10.0, *)) {

                 

                But for some reason, it now gives me Parse Issue Unexpected '@' in program. I tried following https://developer.apple.com/documentation/swift/objective-c_and_c_code_customization/marking_api_availability_in_objective-

                by also trying:

                 

                if #available(iOS 11, *) {

                return [NSLocale currentLocale].languageCode;

                  } else {

                    return nil;

                  }

                }

                 

                Both don't work. I would try fixing the problems, but more problems followed as such: (in attempt order)

                1. (parse issue, expected '(' after 'if'):

                 

                if #available(iOS 10.0, *) {

                    return [NSLocale currentLocale].languageCode;

                  } else {

                    return nil;

                  }

                }

                 

                2. (parse issue, expected expression)

                 

                if (#available(iOS 10.0, *) {

                    return [NSLocale currentLocale].languageCode;

                  } else {

                    return nil;

                  }

                }

                 

                I've been struggling with this and have asked a lot of other friends who code, but unfortunatly no one solved it for me. Help is greatly appreciated. Thanks ahead of time!

                 

                P.S. I know that this is hard to follow, sorry about that!

                  • Re: Parse issue, Expected ')'
                    janabanana Level 1 Level 1 (0 points)

                    KMT gave you the solution.

                     

                    2. (parse issue, expected expression)

                     

                    if (#available(iOS 10.0, *) {

                        return [NSLocale currentLocale].languageCode;

                      } else {

                        return nil;

                      }

                    } << THIS SHOULD NOT BE HERE!  THIS IS GIVING YOU THE ERROR!  DELETE THIS!

                     

                    For every (  you need a ) to match it.

                     

                    For every { you need a } to match it. 

                     

                    if (expression) {

                         do this if expression is true.

                    } else {

                         do this if expression is false.

                    }