Useful Swift Extension

extension String {
subscript(i:Int) ->Character {
let index = self.index(self.startIndex, offsetBy: i)
return self[index]
}
}
extension Character {
var unicodeValue: Int {
get {
let s = String(self).unicodeScalars
return Int(s[s.startIndex].value)
}
}
}
extension Int {   var character:Character?{       get {           let u = UnicodeScalar(self)           if(u != nil) {return Character(u!)}           return nil       }
}
}
extension String {    subscript (start:Int,end:Int) ->String {
assert(start < end,"Start can't be bigger than end")
let startIndex = self.index(self.startIndex, offsetBy: start) let endIndex = self.index(self.startIndex, offsetBy: end) return String(self[startIndex..<endIndex]) }}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store