0

I get a startIndex error. The error is "Value of type 'string.index'(aka'string.characterview.index')has no member'advanced". Heres code and an image of the error.

public override final var secureTextEntry: Bool {
    didSet {
        let textFieldArray: [UITextField?] = [numberInputTextField, cvcTextField, monthTextField, yearTextField]
        textFieldArray.forEach({$0?.isSecureTextEntry = secureTextEntry})
    }
}

Image of Error of isfirstresponder

0

1 Answer 1

2

In swift 3 you can no longer use advanced, successor or predecessor, instead you need to use

let indexAfter = someString.index(after: someIndex)
let indexBefore = someString.index(before: someIndex)
let anyOtherIndex = someString.index(someIndex, offsetBy: distance)

so your code should look like this

let index = (hasOverflow) ? 
text.index(text.startIndex, offsetBy: expectedInputLength) :
text.index(text.startIndex, offsetBy: text.characters.count)

As a side note,

text.index(text.startIndex, offsetBy: text.characters.count)

Is actually the same as

text.endIndex

So you can use this instead

let index = (hasOverflow) ? 
text.index(text.startIndex, offsetBy: expectedInputLength) :
text.endIndex
Sign up to request clarification or add additional context in comments.

16 Comments

how would you fix the other error.
I get the same error with a different function
Using the same function: text.index(text.startIndex, offsetBy: fromInclusively) and text.index(text.startIndex, offsetBy: toExclusively) respectively
Have a look at the duplicate question linked above; they explain it well :)
could you help fix it please, I looked at it and it didn't solve my problem. Could you please help fix it
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.