AddAttribute Error in Swift 1.2 (Xcode 6.3)

This worked before upgrading to Swift 1.2 and Xcode 6.3.

var mutString : NSMutableAttributedString = NSMutableAttributedString(string: "K2")
mutString.addAttribute(kCTSuperscriptAttributeName, value:-1, range:NSMakeRange(1, 1))
var result : String = mutString.string

The result should contain the string K2 (with "2" as the index).

But now I get this error:

Cannot be called addAttributeusing argument list of type'(CFString!, value:Int, range:NSRange)'

Please indicate me the correct solution / documentation.

+4
source share
2 answers

Just add "as! String" after kCTSuperscriptAttributeName

+3
source

addAttributeaccepts a list of type arguments (String, value: AnyObject, range: NSRange). The last two seem fine, but you cannot use CFString!with this method.

Swift String Swift 1.2 ( Objective-C). kCTSuperscriptAttributeName String .

0

All Articles