You have many more options! Above my head you can also:
var value = Float(0) lazy var value: Float = 1 var value = {0 + 0 as Float}()
Etc etc. In any case: I assume that these are, for example, variables; This is not clear from your question.
First, let's talk about options: you should (if possible) avoid options, unless you are dealing with a situation where the value may be clearly absent; for example, a view that you sometimes create, or a delegate that is not always set. In my opinion (and, according to smart people, then I, see the Github Swift Style Guide ), you should use the implicitly expanded options ( value: Float! ) As little as possible. We often see them in the Apple APIs because these APIs are accepted from frameworks that were written in Obj-C, which uses nil in different ways. The only time that something needs to be implicitly expanded is optional, when it can only be installed after init , and when it will never be zero; the place that we see most often is in the views loaded from the storyboard, as this happens immediately after the view controller is initialized.
For other templates: if you do not want to set the initial value, I think that initializing to zero is a good, clear template. This is certainly better than using optional if you are not very specific about reporting that this value may not matter at some point in the future.
If you are dealing with something heavier, and then with a floating point (say, an object that is expensive to create an instance), I prefer the lazy template, because if you never access the value before it is assigned, it will never be created. There are currently several compilers on this issue, so at this point it is preferable to use options; Anyway, lazy uses options backstage.
source share