0

I read this thread but it seems have another problem. This code:

if value.range(of: String(formatter.minusSign))?.count > 0 {
    //STH
}

(where formatter is NumberFormatter object and value is String) produce this error in Swift:

Type 'String.Index' does not conform to protocol '_Strideable'

How to solve it?

Piotr Wasilewicz
  • 1,751
  • 2
  • 15
  • 26

1 Answers1

1

You have to check if the range is not nil

if value.range(of: formatter.minusSign) != nil {
    //STH
}

or – preferable if you want to use the range – optional bindings

if let range = value.range(of: formatter.minusSign) {
    // do somthing with the range
}

or simply

if value.contains(formatter.minusSign) {
    //STH
}
vadian
  • 274,689
  • 30
  • 353
  • 361