错误无法使用类型为((Range <string.index>)'的参数列表来调用类型'Range <_>'的初始化程序

时间:2019-01-04 03:37:41

标签: swift

为什么会出现错误,无法调用类型为((Range)'的参数列表的类型为'Range <_>'的初始化程序

extension String {

    subscript (i: Int) -> Character {
        if self.isEmpty {
            return Character("")
        }

        if i > self.characters.count {
            return Character("")
        }

        return self[self.index(self.startIndex, offsetBy: i)]
    }

    subscript (i: Int) -> String {
        if self.isEmpty {
            return ""
        }

        if i > self.characters.count {
            return ""
        }

        return String(self[i] as Character)
    }

    subscript (r: Range<Int>) -> String {
        let start = self.index(self.startIndex, offsetBy: r.lowerBound)
        let end = self.index(start, offsetBy: r.upperBound - r.lowerBound)
        return self[Range(start ..< end)]
    }

}

0 个答案:

没有答案