Created
March 21, 2018 17:43
-
-
Save 50percentgrey/ff50ad6c3ead779815a0ee219a4fed1d to your computer and use it in GitHub Desktop.
joined for AttributedString
This file contains 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
// 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