[英]Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible'
self.textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(),
NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle]
這給出了一個編譯器錯誤,上面寫着Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible'
Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible'
。 我剛開始使用Swift並且無法弄清楚出了什么問題。
問題是NSUnderlineStyle.StyleSingle
是一個Swift枚舉值,它不符合AnyObject
協議。 要解決這個問題,請調用toRaw()
將其轉換為Int
:
self.textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(),
NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.toRaw()]
更新(適用於Xcode 6.1):
函數toRaw()
已被Xcode 6.1中的屬性rawValue
替換。
self.textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(),
NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.