After some time away from Xcode, I got back into it again tonight. Meanwhile, I’ve got Xcode 7 installed and am hitting some differences thanks to Swift 2.

Turns out Swift Strings have been mutable in more ways than one, as it were, in that their implementation has changed significantly. The nature of the changes is aptly described in an Apple blog post and some more details on using them can be found in the standard documentation, which has been updated.

After a little reading and some tinkering, I have updated my right(Int) function to suit.

extension String {
    func right(length : Int) -> String {
        var result = self
        if result.characters.count > length {
            let range = result.startIndex..<result.endIndex.advancedBy(0 - length)
        return result
Categories: Programming


Leave a Reply

Your email address will not be published. Required fields are marked *