Arrays 导致表达式类型不明确的简单函数没有更多上下文-SwiftUI 这个函数应该只得到一个子字符串,但我似乎不能完全得到它。

Arrays 导致表达式类型不明确的简单函数没有更多上下文-SwiftUI 这个函数应该只得到一个子字符串,但我似乎不能完全得到它。,arrays,swift,Arrays,Swift,我尝试了几乎所有类型的组合,但似乎没有任何效果 导致错误的代码: let final=temp.substring(带:9..String{ var temp=字符串(描述:更新) 让final=temp.substring(带:9..这是因为字符串集合未按整数索引。您需要改用String.Index。您还应确保字符串至少包含11个字符,并在返回结果时使用final而不是temp。顺便说一句,带范围的substring不推荐使用。您应该使用下标: func decodeInput(update:

我尝试了几乎所有类型的组合,但似乎没有任何效果

导致错误的代码:
let final=temp.substring(带:9..String{
var temp=字符串(描述:更新)

让final=temp.substring(带:9..这是因为字符串集合未按整数索引。您需要改用String.Index。您还应确保字符串至少包含11个字符,并在返回结果时使用final而不是temp。顺便说一句,带范围的substring不推荐使用。您应该使用下标:

func decodeInput(update: String) -> String? {
    guard update.count > 10 else { return nil }
    let start = update.index(update.startIndex, offsetBy: 9)
    let end = update.index(start, offsetBy: 2)
    return String(update[start..<end])
}
func解码输入(更新:String)->String{
guard update.count>10 else{return nil}
let start=update.index(update.startIndex,offsetBy:9)
let end=update.index(开始,偏移量:2)

返回字符串(更新[开始..你能提供一个例子吗?我查了一下,不知道应该使用哪些参数。在字符串上调用
String(description:)
是没有意义的,不是吗?@MartinR yes Martin copy粘贴并忘记了它
func decodeInput(update: String) -> String {
    var temp = String(describing: update)
    
    
    let final = temp.substring(with: 9..<11)
    
    return String(temp)
}
func decodeInput(update: String) -> String? {
    guard update.count > 10 else { return nil }
    let start = update.index(update.startIndex, offsetBy: 9)
    let end = update.index(start, offsetBy: 2)
    return String(update[start..<end])
}