Cartography icon indicating copy to clipboard operation
Cartography copied to clipboard

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

Open ninjudd opened this issue 9 years ago • 3 comments

I just updated to Swift 2.0, which required adding this to my Podfile for Cartography to compile:

pod 'Cartography', :git => 'https://github.com/robb/Cartography.git'

Now I am running into the following error:

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

Here is the relevant code:

constrain(intro, avatar) { intro, avatar in
    let introMargin = 30.0
    intro.left == intro.superview!.left + introMargin
    intro.right == intro.superview!.right - introMargin
    intro.top == avatar.bottom + 20.0
}

I can fix it by casting introMargin to CGFloat, but that will involve a lot of casting throughout my code. Is there a better solution?

Thanks!

ninjudd avatar Sep 16 '15 22:09 ninjudd

You could declare introMargin as CGFloat?

robb avatar Sep 17 '15 10:09 robb

Yeah. Declaring it as a CGFloat solves the issue. That's what I meant actually :) Casting every use would be crazy.

I'm curious what caused this to change since it worked fine before. Is not working with Double a change in Cartography, or due to something in Swift 2.0?

ninjudd avatar Sep 17 '15 19:09 ninjudd

UIKit and CoreGraphics always use CGFloat for size/dimension, they never use Double. So i think we should use CGFloat here.

namanhams avatar May 13 '16 09:05 namanhams