I am converting my Objective-c code to swift 2 and I am getting the following errors:
Binary operator '&' cannot be applied to operands of type 'UIFontDescriptorSymbolicTraits' and 'UInt32'
Binary operator '|' cannot be applied to operands of type 'UIFontDescriptorSymbolicTraits' and 'UInt32'
This is my code: errors at the if { ... else {
func addOrRemoveFontTraitWithName(traitName: String, andValue traitValue: UInt32, ...) {
var currentAttributesDict : NSDictionary = self.textView.textStorage.attributesAtIndex(selectedRange.location, effectiveRange: nil)
var currentFont : UIFont = currentAttributesDict .objectForKey(NSFontAttributeName) as! UIFont
var fontDescriptor : UIFontDescriptor = currentFont.fontDescriptor()
var fontNameAttribute : NSString = fontDescriptor.objectForKey(UIFontDescriptorNameAttribute) as! NSString
var changedFontDescriptor : UIFontDescriptor
if (fontNameAttribute.rangeOfString(traitName).location == NSNotFound){
var existingTraitsWithNewTrait : UIFontDescriptorSymbolicTraits = fontDescriptor.symbolicTraits | traitValue
changedFontDescriptor = fontDescriptor.fontDescriptorWithSymbolicTraits(existingTraitsWithNewTrait)
} else {
var existingTraitsWithNewTrait : UIFontDescriptorSymbolicTraits = fontDescriptor.symbolicTraits & ~traitValue
changedFontDescriptor = fontDescriptor.fontDescriptorWithSymbolicTraits(existingTraitsWithNewTrait)
}
...
}
And i tried it with "traitValue: UIFontDescriptorSymbolicTraits" for the parameter "traitvalue"
func addOrRemoveFontTraitWithName(traitName: String, andValue traitValue: UIFontDescriptorSymbolicTraits, ...)
Now the errors are
Binary operator '|' cannot be applied to two 'UIFontDescriptorSymbolicTraits' operands
Unary operator '~' cannot be applied to an operand of type 'UIFontDescriptorSymbolicTraits'
This error was already posted here, but no solution for me. It drives me crazy...:-(
Use the rawValue which is UInt32