How do I make attributed string in Swift?


let attributedString = NSMutableAttributedString(string: "calculation : \(data.cal)g", attributes: [
.font: UIFont.systemFont(ofSize: 14.0, weight: .semibold),
.foregroundColor: UIColor(red: 0.0, green: 118.0 / 255.0, blue: 1.0,
alpha: 1.0),
.kern: 0.0
])
attributedString.addAttributes([
.font: UIFont.systemFont(ofSize: 14.0, weight: .medium),
.foregroundColor: UIColor(white: 0.0, alpha: 1.0)
], range: NSRange(location: 0, length: 5))

How to use :
yourlabel.attributedText = attributedString