Skip to content

Instantly share code, notes, and snippets.

@50percentgrey
Created March 21, 2018 17:43
Show Gist options
  • Save 50percentgrey/ff50ad6c3ead779815a0ee219a4fed1d to your computer and use it in GitHub Desktop.
Save 50percentgrey/ff50ad6c3ead779815a0ee219a4fed1d to your computer and use it in GitHub Desktop.
joined for AttributedString
// split / join for attributed string
extension Sequence where Iterator.Element: NSAttributedString {
func joined(separator: NSAttributedString = NSAttributedString(string: "")) -> NSAttributedString {
var isFirst = true
return self.reduce(NSMutableAttributedString()) {
(r, e) in
if isFirst {
isFirst = false
}
else {
r.append(separator)
}
r.append(e)
return r
}
}
func joined(separator: String = "") -> NSAttributedString {
let separator = NSAttributedString(string: separator)
return joined(separator: separator)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment