Skip to content

Instantly share code, notes, and snippets.

@wanbok
Created August 16, 2016 06:12
Show Gist options
  • Save wanbok/d8b8508e7888edaacfb39f7ba23000c3 to your computer and use it in GitHub Desktop.
Save wanbok/d8b8508e7888edaacfb39f7ba23000c3 to your computer and use it in GitHub Desktop.
join for NSAttributedString
extension CollectionType where Self.Generator.Element : NSAttributedString {
func join(separator: String? = nil) -> NSAttributedString {
let mutableAttributedString = NSMutableAttributedString()
self.forEach {
if let separator = separator where self.first != $0 {
mutableAttributedString.appendAttributedString(NSAttributedString(string: separator))
}
mutableAttributedString.appendAttributedString($0)
}
return mutableAttributedString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment