Home > Software design >  Code works on Xcode 12.5 but not Xcode 12.4
Code works on Xcode 12.5 but not Xcode 12.4

Time:01-27

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?

CodePudding user response:

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.

  •  Tags:  
  • Related