     }
     
     func fittingSubstring(_ width: CGFloat, font: UIFont) -> String {
-        for i in stride(from: characters.count, to: 0, by: -1) {
+        for i in stride(from: count, to: 0, by: -1) {
             let substr = self[0..<i]
             if substr.width(font) <= width {
                 return substr

extension String {
    
    subscript (i: Int) -> Character {
        return self[characters.index(startIndex, offsetBy: i)]
    }
    
    subscript (i: Int) -> String {

    func truncate(_ width: CGFloat, font: UIFont) -> String {
        let ellipsis = "..."
        let substr = fittingSubstring(width - ellipsis.width(font), font: font)
        if substr.count != count {
            return "\(substr.trim())\(ellipsis)"
        } else {
            return self
