Charly Pico Charly Pico - 2 months ago 51
iOS Question

Ambiguous Reference: UITextField.text error Swift 3

So I've just updated to Xcode 8 and converted my Swift 2.3 code to Swift 3, and I have an error in this line of code that wasn't in Swift 2.3:

let holder:NSString! = NSString.init(string: moneyBar.text!).substring(with: NSRange.init(location: y, length: 1))


Now in Swift 2.3 the line has no error, but in Swift 3 it looks like the
moneyBar.text!
is marked with the error
Ambiguous reference to member 'text'.


Is this a Swift 3 bug? Or I'm missing something?

Answer

I think the syntax you want is:

let holder = NSString(string: moneyBar.text!).substring(with: NSRange(location: y, length: 1))
Comments