title: What is the point of using implicitly unwrapped optional in this example?
body: <p>This is from the docs, section <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID203" rel="nofollow noreferrer">Failable Initializers for Classes</a>:</p>
  
  <pre><code>class Product {
  
       let name: String!
       init?(name: String) {
             self.name = name
             if name.isEmpty { return nil }
       }
  }
  
  
  if let bowTie = Product(name: "") {
     // no need to check if bowTie.name == nil
     print("The product's name is \(bowTie.name)")
  }
  </code></pre>
  
  <p>This is described like:</p>
  
  <blockquote>
    <p>In the example above, the name property of the Product class is
    defined as having an implicitly unwrapped optional string type
    (String!). Because it is of an optional type, this means that the name
    property has a default value of nil before it is assigned a specific
    value during initialization. This default value of nil in turn means
    that all of the properties introduced by the Product class have a
    valid initial value. As a result, the failable initializer for Product
    can trigger an initialization failure at the start of the initializer
    if it is passed an empty string, before assigning a specific value to
    the name property within the initializer.</p>
  </blockquote>
  
  <p>Take a look at the last sentence:</p>
  
  <blockquote>
    <p>As a result, the failable initializer for Product
    can trigger an initialization failure at the start of the initializer
    if it is passed an empty string, before assigning a specific value to
    the name property within the initializer.</p>
  </blockquote>
  
  <p>This can't be seen from the provided code . In the provided code, it can be seen that assignment has occurred before <code>return nil</code> part, and either String (non-optional) or String? (optional) would work.</p>
  
  <p>Another thing is that in provided example, it make no sense to use an implicitly unwrapped optional if it is defined as constant. Constants have to be initialized to default values right before the init is finished.  </p>
  
  <p>Any thoughts on this, or does anybody see the reason not to file a radar about this? Maybe I am missing something ? I have an idea actually why is implicitly unwrapped optional used in here, but it is a bad example. For me, this would make more sense:</p>
  
  <pre><code>class Product {
  
      var name: String! //let is changed to var
  
      init?(name: String) {
  
         if name.isEmpty { return nil } //Check here if passed value is non-empty
         self.name = name
      }
  }
  </code></pre>
  
  <p>This way, a initialization failure can be triggered before the any assignment to the <code>name</code> property.</p>