Type 'String.Index' Does Not Conform Protocol 'Integerliteralconvertible'

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

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
}

Type 'String.Index' does not conform protocol 'IntegerLiteralConvertible'

In beta 4, Swift's String.Index handling changed yet again -- you now can't supply an Int when a String.Index is expected. The way to handle it is by creating the String.Index you need using the advance method:

if !name.isEmpty {
var splitted: [String] = name.componentsSeparatedByString(" ")

for curPart in splitted {
if !curPart.isEmpty {
acronym += curPart.substringToIndex(advance(curPart.startIndex, 1))
}
}
if countElements(acronym) > 2 {
acronym = acronym.substringToIndex(advance(acronym.startIndex, 2))
}
}

This is all based on making sure Unicode strings are handled properly - since different Unicode characters can have different sizes, pure integer indexing would hide the fact that Strings aren't random access.

Swift 3.1 UITextField Type 'String.Index' (aka 'String.CharacterView.Index') does not conform to protocol '_Strideable'

I ran into the same problem recently and the solution that worked for me was to check if non of the characters match the inverted set of my allowed characters rather than to check if all characters match the allowed characters set. Below piece of code worked perfectly for me.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let allowedCharacterSet = CharacterSet.letters
if string.isEmpty {
return true
} else if string.rangeOfCharacter(from: allowedCharacterSet.inverted) != nil { //check if the input contains anything else than letters
return false
} else {
return true
}
}

Type 'VideoView' does not conform to protocol 'UIViewRepresentable'

Remove some from return type

func makeUIView(context: Context) -> WKWebView {   // << here !!
return WKWebView()
}


Related Topics



Leave a reply



Submit