2015-10-12 56 views
0

我遷移代碼的XCode 6.4〜7,似乎這個錯誤不會分辨。不能調用類型NSAttributedString初始化與類型的參數列表(字符串:字符串,屬性:[NSObject的:AnyObject]?)

func onHoldReasonAttributedTextSetup(onHoldReson : String) -> NSMutableAttributedString 
{ 

    let markerFontAttributes : [NSObject : AnyObject]? = [ 
     NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!, 
     NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0) 
    ] 
    let onHoldText = NSAttributedString(string: "On Hold: ", attributes: markerFontAttributes) 
    let onHoldReasonText = NSAttributedString(string:onHoldReson) 
    var string = NSMutableAttributedString() 
    string.appendAttributedString(onHoldText) 
    string.appendAttributedString(onHoldReasonText) 
    return string 
} 
+0

使用像'讓markerFontAttributes = [ NSFontAttributeName:UIFont(名: 「HelveticaNeue」,大小:12.0)! NSForegroundColorAttributeName:的UIColor(紅色:0/255,綠色:255分之152,藍色:二百五十五分之二百○四,α-:1.0) ]' –

回答

1

你需要改變這一行:

let markerFontAttributes : [NSObject : AnyObject]? = [ 
     NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!, 
     NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0) 
    ] 

let markerFontAttributes : [String : AnyObject]? = [ 
     NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 12.0)!, 
     NSForegroundColorAttributeName : UIColor(red: 0/255, green: 152/255, blue: 204/255, alpha: 1.0) 
    ] 

因爲初始化器預計歸屬辭典[String : AnyObject]?格式:

init(string str: String, attributes attrs: [String : AnyObject]?) 

參考:NSAttributedString Class Reference

+1

您CAL也完全放棄類型聲明,夫特2應該正常推斷的類型。 – Moritz

+0

@EricD。是的,你是對的。在這種情況下,不需要指定類型 –

相關問題