Search code examples
swiftambiguous

Function type has ambiguous reference to member nextInt()


My intent is to use nextInt(upperBound: Int)

let randomInt: (Int) -> Int = GKRandomSource.sharedRandom().nextInt
var myNumber = randomInt(10)

Produce error: Playground execution failed: error: ambiguous reference to member 'nextInt()'

Why?

Swift 3, xCode 8 beta 6


Solution

  • Your code compiles fine in a real iOS app, as shown by this screen shot:

    enter image description here

    That, an actual iOS app project, is the real test of whether code is valid. Playgrounds do not represent real Swift environments.