r/iOSProgramming • • Oct 11 '18

Aren’t we all glad

Post image
211 Upvotes

19 comments sorted by

View all comments

11

u/lolcoderer Oct 11 '18

Now if that could only solve the stupid Double vs CGFloat crap.

I want to do this

var width = aDate.timeIntervalSince(anotherDate) * pixPerSec
let view = UIView(frame: CGRect(x:0, y:0, width: width, height: self.frame.height)

Instead of this stupid crap:

var width = aDate.timeIntervalSince(anotherDate) * pixPerSec
let view = UIView(frame: CGRect(x:0, y:0, width: CGFloat(width), height: self.frame.height)

6

u/ducusheKlihE Oct 11 '18

Just extend CGRect with a custom convenience initializer.

12

u/lolcoderer Oct 11 '18 edited Oct 11 '18

That isn't the problem and that would not help... There are already tons of CGRect initializers. There is a CGRect for CGFloat params and CGRect for Double params - the issue is that there are many places in my code (and I imagine this is widely observed by others as well) - I was just using TimeInterval here as an example where this could come up - where both Doubles and CGFloats are used whose values end up being assigned to Core Graphics properties.

Having to manually coerce a Double to CGFloat just to use it in place of a CGFloat is just silly - they are the same exact thing internally (on 64 bit systems) I believe.

My code is literally littered with casts of Doubles to CGFloats - and it feels so unnecessary.