Typically when creating a frame for a view I use CGRect where the parameters accepts CGFloat, Double or Int. They all create a rectangle with coordinates and dimensions specified as a CGFloat, Int or Double (summarized from Apple Doc), but does it matter which type of value you choose to use? Is there some underlying difference in choosing one option over the other. Is it the way they use memory differently?
Asked
Active
Viewed 54 times
0
-
That will depend on your needs. They are convenience initialisers. Int and Double are preferred. – Leo Dabus Mar 25 '19 at 21:52
-
2It's basically handling the dirty work so you don't have to convert them to a single type before hand. – keji Mar 25 '19 at 21:54
1 Answers
0
There shouldn't be any difference.
Those are convenience initializers. That means you can have inits with different parameters/parameter types.
But, of course, if you want to create a CGRect
with edges that are not Int
(if you want real numbers), than you will need to use the init
with Double
or CGFloat
parameters (even though the syntax will look pretty much the same, behind the scenes, the initializer for that specific type will be called).

Toma Radu-Petrescu
- 2,152
- 2
- 23
- 57