I´m still trying to convert TextKit from Objective-C to Swift. It drives me (and you ?) crazy :-( After fixing some problems, now i´m having trouble with the bold (and italic) font:
func addOrRemoveFontTraitWithName(traitName: String, andValue traitValue: UInt32, andRange selectedRange: NSRange) {
let currentAttributesDict : NSDictionary! = self.textView.textStorage.attributesAtIndex(selectedRange.location, effectiveRange: nil)
let currentFont : UIFont = currentAttributesDict .objectForKey(NSFontAttributeName) as! UIFont
...
var existingTraitsWithNewTrait : UInt32! = nil
var changedFontDescriptor : UIFontDescriptor! = nil
if fontNameAttribute.rangeOfString(traitName).location == NSNotFound {
existingTraitsWithNewTrait = fontDescriptor.symbolicTraits.rawValue | traitValue
changedFontDescriptor = fontDescriptor.fontDescriptorWithSymbolicTraits(UIFontDescriptorSymbolicTraits.TraitBold)
} else {
existingTraitsWithNewTrait = fontDescriptor.symbolicTraits.rawValue & ~traitValue
changedFontDescriptor =
fontDescriptor.fontDescriptorWithSymbolicTraits(existingTraitsWithNewTrait) // !!!!
}
In the last line i get the error Cannot convert value of type 'UInt32!' to expected argument type 'UIFontDescriptorSymbolicTraits'
Must i convert UInt32 to UIFontDescriptorSymbolicTraits? The other way is to use .rawValue. But i dont know, how to do this. :-(
Any help is welcome!