Re: CGFloat and literal floats in Swift

2015-07-26 Thread Tim Fletcher
Slightly off topic; I would love to see some form of what Scala calls implicits in swift. For exactly this reason. On Mon, 27 Jul 2015 05:10 Rick Mann wrote: > > > On Jul 26, 2015, at 20:57 , Jens Alfke wrote: > > > > > >> On Jul 26, 2015, at 4:50 PM, Quincey Morris < > quinceymor...@rivergates

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
> On Jul 26, 2015, at 20:57 , Jens Alfke wrote: > > >> On Jul 26, 2015, at 4:50 PM, Quincey Morris >> wrote: >> >> No. Swift doesn’t convert between numeric types automatically, so Double —> >> CGFloat produces an error. > > I’m guessing this is only a problem when building 32-bit? Because

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Jens Alfke
> On Jul 26, 2015, at 4:50 PM, Quincey Morris > wrote: > > No. Swift doesn’t convert between numeric types automatically, so Double —> > CGFloat produces an error. I’m guessing this is only a problem when building 32-bit? Because in 64-bit, CGFloat is equivalent to Double, so there shouldn’t

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 17:42 , Rick Mann wrote: > > So, why can I do this? > > let n : NSNumber = M_PI That’s bridged, not converted. :) The Swift compiler has built-in knowledge of what can be bridged, and does a typecast or value conversion according to context. __

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
> On Jul 26, 2015, at 16:50 , Quincey Morris > wrote: > > On Jul 26, 2015, at 16:38 , Rick Mann wrote: >> >> So, is a literal 0.0 not of type Double? > > No, it’s a numeric literal, so it has no numeric type. However your ‘addArc’ > function requires CGFloat parameters. Literal 0.0 is conv

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 16:38 , Rick Mann wrote: > > So, is a literal 0.0 not of type Double? No, it’s a numeric literal, so it has no numeric type. However your ‘addArc’ function requires CGFloat parameters. Literal 0.0 is convertible to CGFloat, but Double M_PI isn’t convertible automatically.

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
> On Jul 26, 2015, at 16:34 , Quincey Morris > wrote: > > On Jul 26, 2015, at 16:29 , Rick Mann wrote: >> >> addArc(CGPoint(x: 0, y: 0), 50.0, 0.0, M_PI) > > The problem in this case is that M_PI is a Double variable in Swift, not a > compile time constant like in Obj-C. You will unfortunat

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 16:29 , Rick Mann wrote: > > addArc(CGPoint(x: 0, y: 0), 50.0, 0.0, M_PI) The problem in this case is that M_PI is a Double variable in Swift, not a compile time constant like in Obj-C. You will unfortunately have to wrap it in CGFloat(), then the constants should work fine

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
Also weird, I only have to cast the last two arguments, not the second. > On Jul 26, 2015, at 16:07 , Quincey Morris > wrote: > > On Jul 26, 2015, at 15:57 , Rick Mann wrote: >> >> I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, >> because the compiler won't let me

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
> On Jul 26, 2015, at 16:07 , Quincey Morris > wrote: > > On Jul 26, 2015, at 15:57 , Rick Mann wrote: >> >> I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, >> because the compiler won't let me pass a floating-point literal to a >> parameter that takes a CGFloat. I

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 15:57 , Rick Mann wrote: > > I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, > because the compiler won't let me pass a floating-point literal to a > parameter that takes a CGFloat. I have to wrap them all in CGFloat(). I’m not seeing this. Do you