İşte Swift 2'de Int
tarafından dizine edilemedi
label1.text = String(name2[name2.startIndex])
olan fonksiyonları bir çift var Bu, daha fazla objektif hale getiriyor
func substringOfString(_ s: String, toIndex anIndex: Int) -> String
{
return s.substring(to: s.index(s.startIndex, offsetBy: anIndex))
}
func substringOfString(_ s: String, fromIndex anIndex: Int) -> String
{
return s.substring(from: s.index(s.startIndex, offsetBy: anIndex))
}
//examples
let str = "Swift's String implementation is completely and utterly irritating"
let newstr = substringOfString(str, fromIndex: 30) // is completely and utterly irritating
let anotherStr = substringOfString(str, toIndex: 14) // Swift's String
let thisString = substringOfString(anotherStr, toIndex: 5) // Swift
Bkz. [H ow, String.Index, Swift 3'te çalışır (http://stackoverflow.com/questions/39676939/how-does-string-index-work-in-swift-3) ve [String 3'te Swift dizisi nasıl çalışır?] (http://stackoverflow.com/questions/39677330/how-does-string-substring-work-in-swift-3) – Hamish