Swift 3 error: [_SwiftValue pointSize] unrecognized selector sent to instance
If I use your test code, but let the data type of attributes
default, it doesn't crash. That is:
let attributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 14)]
Option-clicking on the variable says it's [String : UIFont]
.
A little extra testing, suggests that it's related to the optional object; [String: AnyObject]
appears to work OK.
EDIT:And after all that, I decided to read the documentation, which says to use [String: Any]
. :)
func attributedString(firstText : String, amount : String, fontSize : CGFloat, color : UIColor) -> NSAttributedString { let attrDict = [ NSFontAttributeName : UIFont(name: fontRegular, size: CGFloat(fontSize/2))!, NSForegroundColorAttributeName : UIColor.darkGray] as [String : AnyObject] let iconString = NSMutableAttributedString(string: firstText, attributes: attrDict) let attrDict1 = [ NSFontAttributeName : UIFont(name: fontRegular, size: CGFloat(fontSize))!, NSForegroundColorAttributeName : color] as [String : AnyObject] let amountString = NSMutableAttributedString(string: amount, attributes: attrDict1) iconString.append(amountString) return iconString}
And call it like
lblBalanceAmount.attributedText = self.attributedString(firstText: "My Balance", amount: "500", fontSize: newFontSize, color : UIColor(red: 41/255.0, green: 192/255.0, blue: 42/255.0, alpha: 1.0))