我试图遵循一个快速的教程,但我有最新版本,教程是在以前的版本。我无法解决语法,因为我对swift知之甚少,我正在开始。
行:let color = UIColor(CGColor: selectedButton?.layer.backgroundColor)
错误:
可选类型的值CGColor =未展开;你是否愿意使用'!'要么 '?'用'(selectedButton?.layer.backgroundColor)替换selectedButton?.layer.backgroundColor!'
我已经替换了这个:
let color = UIColor(CGColor: (selectedButton?.layer.backgroundColor)!)
现在出现下一个错
模糊地使用'init(CGColor)'
正确的方法是
if let color = selectedButton.backgroundColor {
// use color in here
}
但是出于教学目的,只需使用
let color = selectedButton.backgroundColor!