Created
March 26, 2019 22:03
-
-
Save DaveWoodCom/0c801d24ca6c0148b65e90a6d1402048 to your computer and use it in GitHub Desktop.
Radar #?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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