无法转换类型'UInt32!'的值预期参数类型“UIFontDescriptorSymbolicTraits”
问题描述:
I'm仍试图从TextKit Objective-C的转换为斯威夫特。 (?和你)这让我发疯:-( 修复了一些问题后,现在i'm具有大胆(斜体)字体麻烦:无法转换类型'UInt32!'的值预期参数类型“UIFontDescriptorSymbolicTraits”
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) // !!!!
}
在最后一行我得到错误 无法将类型“UInt32的!”到期望的参数类型的值“UIFontDescriptorSymbolicTraits”
我必须转换UInt32的到UIFontDescriptorSymbolicTraits?另一种方法是使用.rawValue。但我不知道,该怎么办这个。:-(
欢迎任何帮助!
答
尝试UIFontDescriptorSymbolicTraits(rawValue: existingTraitsWithNewTrait)
代替existingTraitsWithNewTrait
错误线。
+0
嘿普拉迪普,that's它,我underdtand它;-) 非常感谢! –
请停止添加不适当的标签。这个问题是关于Swift代码的问题。这个问题不是关于Objective-C的问题。 – rmaddy
@rmaddy:有做我使用的Objective-C? –