我是Swift的新手(使用Swift 4.1) . 我正在学习一些教程,试图学习语法 . 在代码行中:
if !message.isSender!.boolValue
我收到一个错误说:
无法强制解包非可选类型'Bool'的值
我已经四处浏览,无法找到或找出错误的解决方案 .
if !message.isSender!.boolValue {
cell.messageTextView.frame = CGRect(x: 48 + 8, y: 0, width: estimatedFrame.width + 16, height: estimatedFrame.height + 20)
cell.textBubbleView.frame = CGRect(x: 48, y: 0, width: estimatedFrame.width + 16 + 8, height: estimatedFrame.height + 20)
} else {
cell.messageTextView.frame = CGRect(x: 48 + 8, y: 0, width: estimatedFrame.width + 16, height: estimatedFrame.height + 20)
cell.textBubbleView.frame = CGRect(x: view.frame.width - estimatedFrame, y: 0, width: estimatedFrame.width + 16 + 8, height: estimatedFrame.height + 20)
}
1 回答
因为它已经是Bool,所以只需使用它:
有's no reason to unwrap, it'不是可选的,因为编译器's telling you, and there'没有理由为简单的
if
访问boolValue
.