Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created March 9, 2021 14:44
Show Gist options
  • Save trilliwon/daf5f5d4447e91d77bb1161e318b4fa9 to your computer and use it in GitHub Desktop.
Save trilliwon/daf5f5d4447e91d77bb1161e318b4fa9 to your computer and use it in GitHub Desktop.
import Foundation
@_functionBuilder
public class NSAttributedStringBuilder {
public static func buildBlock(_ components: NSAttributedString...) -> NSAttributedString {
let att = NSMutableAttributedString(string: "")
return components.reduce(into: att) { $0.append($1) }
}
}
public extension NSAttributedString {
class func composing(@NSAttributedStringBuilder _ parts: () -> NSAttributedString) -> NSAttributedString {
parts()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment