2017-12-20 7 views
0

私は素早いチュートリアルに従おうとしていますが、私は最新バージョンを持っており、チュートリアルは以前のバージョンです。私は文法を解くことができません。なぜなら私は迅速なことをあまり知らないので、私は始めています。エラーsintax UIColor(CGColor:selectedButton?.layer.backgroundColor)Swift

ライン: let color = UIColor(CGColor: selectedButton?.layer.backgroundColor)

エラー:

let color = UIColor(CGColor: (selectedButton?.layer.backgroundColor)!) 

今、次のエラー:

Ambiguous use of 'init(CGColor)'

+0

を使用しています。正しいメソッドは 'UIColor(cgColor:)'です。 Xcodeのオートコンプリートは、メソッドのシグネチャについてはわかりません。 –

+0

ありがとう!私はこのエラーを解決することができます! –

答えて

0

Value of optional type CGColor= not unwrapped; did yoy mean to use '!' or '?' Replace selectedButton?.layer.backgroundColor with '(selectedButton?.layer.backgroundColor)!'

私はすでにこれを置き換えますそれを行うための正しい方法は

if let color = selectedButton.backgroundColor { 
    // use color in here 

} 

しかし、チュートリアルの目的のためになるだけであなたはあなたのコードのタイプミスを持って

let color = selectedButton.backgroundColor!