Skip to content

Instantly share code, notes, and snippets.

@DaveWoodCom
Created March 26, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveWoodCom/0c801d24ca6c0148b65e90a6d1402048 to your computer and use it in GitHub Desktop.
Save DaveWoodCom/0c801d24ca6c0148b65e90a6d1402048 to your computer and use it in GitHub Desktop.
Radar #?
Here's some sample code that works fine in Xcode 10.1, but fails to compile in 10.2 even though it's valid code.
The #if/#else/#endif code seems to be confusing the compiler and thus it is mixing up scope.
Xcode Version 10.2 (10E125) -> Broken
Xcode Version 10.1 (10B61) -> Works correctly
// This variable uses #if to create two possible code paths, in this example, it's just using `true`, but
// in my real project it uses a variable defined in the Scheme. The result is the same.
// The error here is that Xcode is disallowing the use of the variable name `firstVar` inside the braces
// which is perfectly valid code. You can see it work correctly below in `secondVar`.
let firstVar: String = {
#if true
let firstVar: String = "One"
#else
let firstVar: String = "Two"
#endif
return firstVar // Variable used within its own initial value
}()
// This variable breaks down to the exact same code, but without the #if and it works correctly.
let secondVar: String = {
let secondVar: String = "Three"
return secondVar // Essentially the same code, but with no error
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment