Chop off trailing newline for Swift's NSAttributedString
Your method works correctly, as far as I can see.

For a read-only computed property, you don't need to enclose the
getter method in get {  }:

var trailingNewlineChopped: NSAttributedString {
    guard self.length &gt; 0 else {
        return self
    }
    let lastCharRange = NSMakeRange(self.length - 1, 1)
    let lastChar = self.attributedSubstringFromRange(lastCharRange).string
    guard lastChar == "\n" else {
        return self
    }
    let mutableCopy = NSMutableAttributedString(attributedString: self)
    mutableCopy.deleteCharactersInRange(lastCharRange)
    return mutableCopy
}


Checking for a trailing newline character can be done with
the hasSuffix() method on the underlying string.

Instead of creating a mutable copy and removing the last character,
you can extract the first length-1 characters instead.

The method then becomes

var trailingNewlineChopped: NSAttributedString {
    if self.string.hasSuffix("\n") {
        return self.attributedSubstringFromRange(NSMakeRange(0, self.length - 1))
    } else {
        return self
    }
}


You can even omit the implicit self., but that is a matter of personal
preference:

var trailingNewlineChopped: NSAttributedString {
    if string.hasSuffix("\n") {
        return self.attributedSubstringFromRange(NSMakeRange(0, length - 1))
    } else {
        return self
    }
}


NSMakeRange will not be available in Swift 3 anymore, so it could
be a good idea to start replacing that by
NSRange(location:, length:) in your code.



Update: Swift 3 changed how Objective-C methods are imported
into Swift:

extension NSAttributedString {

    var trailingNewlineChopped: NSAttributedString {
        if string.hasSuffix("\n") {
            return self.attributedSubstring(from: NSRange(location: 0, length: length - 1))
        } else {
            return self
        }
    }
}