Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Code works on XCode 12.5 but not XCode 12.4

This code compiles fine on XCode 12.5.1 and 13

private func maskOtherLocalAccount(number: String?) -> String {
    guard let number = number, number.count > 5 else { return number ?? "-"}
}

But on XCode 12.4, it gives this compile error:

Variable declared in 'guard' condition is not usable in its body

Though the fix is quite easy, I find it really strange that it works on XCode 12.5.1 and not on 12.4.
Can someone point to an official changelog documenting this change?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is reported by SR-8669:

If you attempt to use a guard statement to declare a variable that shadows an existing variable, a compiler error prevents you from accessing the existing variable in the body of the guard.

This is already marked resolved almost a whole year ago, which matches the release date of Xcode 12.5.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading