0
我想爲下面的代碼片段中的UIColor創建一個Type擴展,但我收到一個構建錯誤。當我嘗試在我的Type擴展方法中創建UIColor對象時,UIColor構造函數引用了我創建的封裝UIColor擴展。如何在我的UIColor Type擴展方法中實例化UIColor對象?如何在類型擴展方法中實例化類型?
// Error: "Argument to call takes no parameters"
import UIKit
import Foundation
extension UIColor {
class UIColor {
var seventyPercentGreyColor : UIColor {
get {
let seventyPercent:CGFloat = (1.0 - 0.70)
// The below line of code produces a
// "Argument to call takes no parameters" build error
let color = UIColor(red: seventyPercent, green: seventyPercent, blue: seventyPercent, alpha:1.0)
return color
}
}
}
}
刪除'類的UIColor {}' - 你想'類VAR seventyPercentGreyColor:的UIColor {...}',而不是(你可以也刪除顯式的'get {}') – Hamish