Skip to content

Instantly share code, notes, and snippets.

@exPHAT
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exPHAT/5505bbd094300538e6b0 to your computer and use it in GitHub Desktop.
Save exPHAT/5505bbd094300538e6b0 to your computer and use it in GitHub Desktop.
A simple subscript to allow python-like string slicing.
// Example: mystring[0] or mystring[2,6]
import Cocoa
extension String {
subscript(index:Int) -> Character {
get {
return Character(bridgeToObjectiveC().substringWithRange(NSMakeRange(index,1)))
}
}
subscript(start:Int, end:Int) -> String {
get {
return String(bridgeToObjectiveC().substringWithRange(NSMakeRange(start, end-start)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment