Max MacLeod
Max MacLeod

Reputation: 26652

Why Does Xcode Show "Ambiguous use of 'myMethod' When Implementing Fallback Using @available?

In implementing fallback instance methods for methods using @available(iOS 8.0, *), Xcode shows a built error:

"Ambiguous use of 'myMethod'...

along with two candidate methods highlighted.

This is despite using the @available directive.

For example:

@available(iOS 8.0, *)
func getURLParameter() -> NSURLQueryItem 
{
   return NSURLQueryItem(name: "name", value: "John")
}

func getURLParameter() -> Dictionary<String, String>
{
   return ["name" : "John"]
}

let param = getURLParameter()

The @available works successfully elsewhere with methods identically named. Why does it fail in this case?

Upvotes: 2

Views: 385

Answers (1)

D&#225;niel Nagy
D&#225;niel Nagy

Reputation: 12015

Above or equal to iOS 8, both getURLParameter methods are available, and if you declare your param variable without type, the compiler will not be able the choose between the methods.

Upvotes: 2

Related Questions