Charly Pico Charly Pico - 1 year ago 333
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
is marked with the error
Ambiguous reference to member 'text'.

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

Answer Source

I think the syntax you want is:

let holder = NSString(string: moneyBar.text!).substring(with: NSRange(location: y, length: 1))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download