我是Swift的新手(使用Swift 4.1)。我正在遵循一些教程来尝试学习语法。在代码行中:
if !message.isSender!.boolValue
我收到一条错误消息:
无法强制打开非可选类型“布尔”的包装值
我到处冲浪,无法完全找到或解决错误的解决方法。
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)
}
答案 0 :(得分:1)
由于它已经是布尔,只需使用它即可:
if !message.isSender
没有理由解包,编译器告诉您这不是可选的,也没有理由为简单的boolValue
访问if
。