iOS--Swift 3--SwiftAlertView--可选类型

标签 ios swift

我使用第三方 SwiftAlertView 类(https://github.com/dinhquan/SwiftAlertView)并将 Swift 从 2.3 更新到 3。
当我遵守时,应用程序和我发现错误消息如下。

 Binary operator '+' cannot be applied to operands of type 'Double' and 'Double!'

代码如下。
titleTopMargin和titleToMessageSpacing是Double!
那不能加Double(titleLabel.frame.size.height)。

let topPartHeight = (contentView == nil) ? (titleTopMargin + Double(titleLabel.frame.size.height) + titleToMessageSpacing + Double(messageLabel.frame.size.height) + messageBottomMargin) : Double(contentView!.frame.size.height)

定义如下。

// customize the margin & spacing of title & message
open var titleSideMargin: Double!  // default is 20 px
open var messageSideMargin: Double!  // default is 20 px
open var titleTopMargin: Double!  // default is 20 px
open var messageBottomMargin: Double! // default is 20 px
open var titleToMessageSpacing: Double! // default is 10 px

我该如何解决这个问题?

谢谢。

最佳答案

谢谢大家给我的建议。

这些变量还是需要用Double。所以我需要更新以下代码。

open var titleSideMargin: Double = 20.0
open var messageSideMargin: Double = 20.0
open var titleTopMargin: Double = 20.0
open var messageBottomMargin: Double = 20.0
open var titleToMessageSpacing: Double = 10.0

关于iOS--Swift 3--SwiftAlertView--可选类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39784299/

相关文章:

ios - iTunes 的搜索 API 通过提供应用程序名称而不是查找 ID 来检索应用程序

ios - Swift:didExitRegion 延迟导致错过信标事件

swift - 如何在滚动 UITableView 期间制作动画

arrays - 如何找到数组数组中存在的整数?

ios - 尝试将指针转换为 ARC 下的指针

ios - SF Symbol 看起来变形了

swift - 为什么在 Swift 的单数 return 表达式中使用闭包速记变量必须是详尽无遗的?

ios - 无法正确自动调整自动布局和堆栈 View (Swift 3、Xcode 8)

iphone - 如果应用程式意外关闭,应如何重新启动

ios - Swift - 如何获取具有初始值设定项的数组的索引?