0

I use the third party SwiftAlertView class(https://github.com/dinhquan/SwiftAlertView) and update Swift from 2.3 to 3.
When I complied, the app and I found the error message as following.

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

The code is following.
The titleTopMargin and titleToMessageSpacing are Double!
That can't add 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)

The definition is following.

// 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

How do I fix the problem?

Thanks.

kikily liu
  • 37
  • 1
  • 12

3 Answers3

1

Thanks everybody for giving me suggestion.

These variables still need to use Double. So I need to update the following code.

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
kikily liu
  • 37
  • 1
  • 12
0

UIKit and CoreGraphics always use CGFloat for size, they never use to Double type. So, I think we should use to CGFloat here.

Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40
0

Exactly as @Rahul answers. So set type to CGFloat:

var titleSideMargin: CGFloat = 20.0
var messageSideMargin: CGFloat = 20.0
var titleTopMargin: CGFloat = 20.0
var messageBottomMargin: CGFloat = 20.0
var titleToMessageSpacing: CGFloat = 10.0

let topPartHeight = (contentView == nil) ? (titleTopMargin + titleLabel.frame.size.height + titleToMessageSpacing + messageLabel.frame.size.height + messageBottomMargin) : contentView!.frame.size.height
pedrouan
  • 12,762
  • 3
  • 58
  • 74