【发布时间】:2018-06-03 04:58:45
【问题描述】:
我正在尝试学习 swift 教程,但我有最新版本,并且教程在以前的版本中。因为我对swift不太了解,所以无法解决语法问题,我开始了。
行:
let color = UIColor(CGColor: selectedButton?.layer.backgroundColor)
错误:
可选类型 CGColor= 的值未展开;你的意思是用'!'要么 '?'将 selectedButton?.layer.backgroundColor 替换为 '(selectedButton?.layer.backgroundColor)!'
我已经替换了这个:
let color = UIColor(CGColor: (selectedButton?.layer.backgroundColor)!)
现在下一个错误:
'init(CGColor)'的模糊使用
【问题讨论】:
-
您的代码中有错字。正确的方法是
UIColor(cgColor:)。如果您不确定方法签名,您应该依赖 Xcode 的自动完成功能。 -
谢谢!我可以解决这个错误。!