2
votes

Got this piece of code:

if (self.competitionData.competitionList == nil) || (renewCache) {  
    // <things to be done> 
}

where renewCache is a Bool.

I'm getting the following errors on this line:

  • Expected '{' after 'if' condition
  • Braced block of statements is an unused closure
  • Invalid character in source file

but AFAIK I think it's correct. What's the problem?

Thanks.

2
I'm voting to close this question as off-topic because it's a basic syntax error. Would have marked it as "Too Localized" in past revs of SO closing options. - Paul Sasik
I can't do anything to get this code to generate an error (and indeed, the only thing I see that's marginal is enclosing renewCache in parens, which is unnecessary and mostly pointless. If you're still having this problem you need to post the rest of the problem context, a minimum reproducible example. - David Berry
My best guess: remove the text between if and { completely and type it new manually (not copy/paste!). Maybe you got some wrong utf-8 char you can't see. - qwerty_so
I like @ThomasKilian's idea. The third error you listed actually says pretty much what he's saying: Invalid character in source file There are a number of Unicode characters (and therefore UTF-8) which could look like a normal space or even not show up and cause problems with your source code. Did you copy the code from a web page somewhere? - Paul Sasik

2 Answers

1
votes

Well, finally I found the problem.

It's not related with this line at all, but a sentence like 10 lines below in a method call where I was passing the second parameter without parameter name. By the way, that line wasn't marked as error by XCode :-(

it seems that the XCode Swift parser has some problems identifying the correct line of your error.

After fixing the problem, that line is compiled ok.

-2
votes

Try with extra parentheses:

if ((self.competitionData.competitionList == nil) || (renewCache)) {
}

This is the problem, only need extra-parentheses for conditions :)

PD: Sorry, fixed