【发布时间】:2019-01-29 08:01:18
【问题描述】:
我是 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)
}
【问题讨论】:
-
这取决于
message和isSender的定义方式。告诉我们。 -
变量“message”和“isSender”的类型是什么?
-
你唯一强制解包的是
isSender,这是一个非可选的Bool。所以你可能只想要if !message.isSender {。 -
您正在遵循哪些教程告诉您使用
boolValue属性?这在 Swift 中是不寻常的。 -
欢迎来到 Stack Overflow。发帖前请阅读how to ask。除其他事项外,您应该在发帖后闲逛并回复 cmets。