I have the following swift 4.1 code:
let timeduration = NSMutableAttributedString.init(string: "a dynamic string of time");
timeduration.addAttribute(kCTFontAttributeName as NSAttributedStringKey, value: UIFont.systemFont(ofSize: 16), range: NSRange(location: 0, length: timeduration.length));
timeduration.addAttribute(kCTForegroundColorAttributeName as NSAttributedStringKey, value: UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1.0), range: NSRange(location: 0, length: timeduration.length));
timeduration.addAttribute(kCTFontAttributeName as NSAttributedStringKey, value: UIFont.systemFont(ofSize: 50), range: NSRange(location: 0, length: timecount));
timeduration.addAttribute(kCTFontAttributeName as NSAttributedStringKey, value: UIFont.systemFont(ofSize: 25), range: NSRange(location: timecount, length: 2));
I was using Swift 3 and did the migration using Xcode's tool to swift 4.1 but the foreground color doesn't appear to be working. The XCode tool "Fix" added the kCT codes. The font names and sizes seem to be working though.
Here is the solution to your problem. In Swift 4.0 and later, there is struct called NSAttributedStringKey which define the keys for string attributes.
let timeduration = NSMutableAttributedString.init(string: "a dynamic string of time")
timeduration.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 16), range: NSRange(location: 0, length: timeduration.length))
timeduration.addAttribute(NSAttributedStringKey.foregroundColor, value:
UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1.0), range:
NSRange(location: 0, length: timeduration.length))
timeduration.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 50), range: NSRange(location: 0, length: timecount))
timeduration.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 25), range: NSRange(location: timecount, length: 2))