Reputation: 39181
var number = 3
vs
var number: Int = 3
How does using specific types vs type inference affect compile time? Has anyone done experiments or some math on this topic?
Does this runtime affect at all in anyway?
Upvotes: 1
Views: 367
Reputation: 52530
Compile time: In most cases, this will be trivial. In your example, 3 is an integer literal; integer literals can adapt to their use, but it's trivial that number will have type Int.
At runtime, there is absolutely no difference. Both statements are 100 percent equivalent.
Upvotes: 5
Reputation: 780
Both examples will do the same. differences appear when using float values.
var double = 2.5
var float : Float = 2.5
In swift its better to write less code. This makes the code healthier and for sure it will be faster.
Upvotes: 0