錯誤提示:
Swift Compiler Error
'?' must be followed by a call, member lookup, or subscript
報錯代碼:
錯誤代碼.png
解決辦法:
將代碼行 head.backgroundColor = UIColor.hex2RGB("#e9f1f6")
改為:
head.backgroundColor = UIColor.hex2RGB("#e9f1f6") as UIColor
總結:
將代碼: head.backgroundColor = UIColor.hex2RGB("#e9f1f6")分開發(fā)現(xiàn)不報錯了....
Paste_Image.png
注: 為UIColor的增加的OC分類,放在swift里,返回值就變成了可選值,尤其是在閉包里,這個問題屬于編譯器的問題