这在升级到 Swift 1.2和Xcode 6.3之前有效. var mutString : NSMutableAttributedString = NSMutableAttributedString(string: "K2")mutString.addAttribute(kCTSuperscriptAttributeName, value:-1, range:NSMakeRange(1, 1))var result : String
var mutString : NSMutableAttributedString = NSMutableAttributedString(string: "K2") mutString.addAttribute(kCTSuperscriptAttributeName, value:-1, range:NSMakeRange(1, 1)) var result : String = mutString.string
结果应该包含字符串K2(以“2”作为下标).
但是现在我收到了这个错误:
Cannot invoke
addAttribute
with an argument list of type'(CFString!, value:Int, range:NSRange)'
请指出正确的解决方案/文档.
只需在kCTSuperscriptAttributeName之后添加“as!String”即可