Quick Answer
Resolve overloaded function calls.
Understanding the Issue
Swift cannot determine which function overload to use when multiple versions match the call signature.
The Problem
This code demonstrates the issue:
Swift
Error
func process(_ value: Int) {}
func process(_ value: String) {}
process(3.14) // Ambiguous
The Solution
Here's the corrected code:
Swift
Fixed
// Solution 1: Add specific overload
func process(_ value: Double) {}
// Solution 2: Explicit type casting
process(Int(3.14))
// Solution 3: Named parameters
func process(int value: Int) {}
func process(string value: String) {}
process(int: 3)
// Solution 4: Type annotations
let input: Int = 3
process(input)
Key Takeaways
Make overloads distinct or provide explicit types at call sites.