Last active
August 29, 2015 14:18
-
-
Save joanmolinas/79e30af02e25b490f5c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
subscript(index : Int) -> Character{ | |
get { | |
return self[advance(self.startIndex, index)] | |
} set(newValue) { | |
self = self.stringByReplacingCharactersInRange(Range<String.Index>(start: advance(startIndex, index), end: advance(startIndex, index+1)), withString: String(newValue)) | |
} | |
} | |
} | |
var string = "Hello World!" | |
string[4] //OUTPUT -> "o" | |
string[4] = "y" //OUTPUT -> "Helly World!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment