[英]Why am I getting this error : Result values in '? :' expression have mismatching types '[String]?' and 'String'
[英]Why am I getting the error “Cannot assign to the result of this expression” when checking for the class of a sender?
我正在嘗試制作一個函數,該函數將檢查發送方的類並采取相應的措施,但是由於某些原因,我遇到了第一個條件錯誤“無法分配給該表達式的結果”。 有人能啟發我做錯什么嗎? 錯誤出現在clipToBounds
行上。 這是代碼:
func setupContactIcons(sender: AnyObject?) {
if (sender!.isKindOfClass(UIVisualEffectView)) {
sender!.layer.cornerRadius = sender!.frame.size.width/2
sender!.clipsToBounds = true
}
}
獎勵:有更好的方法嗎?
這樣做的更好的辦法是使用if let
連同as?
:
func setupContactIcons(sender: AnyObject?) {
if let view = sender as? UIVisualEffectView {
view.layer.cornerRadius = view.frame.size.width/2
view.clipsToBounds = true
}
}
順帶一提,這也將消除問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.