Junior — Middle
Is it possible to assign a variable a name that matches a function's name?
sobes.tech AI
Answer from AI
In Swift (iOS), you cannot declare a variable with a name that matches the name of a function within the same scope. This will lead to a name conflict and a compilation error, as the compiler will not be able to unambiguously determine whether the code refers to the function or the variable.
For example, the following code will cause an error:
func example() {
let example = 5 // Error: name conflict with function example
}
To avoid this, use different names for functions and variables or place them in different scopes.