title: Swift: optional array count
body: <p>In Objective-C, if I had the following property:</p>
  
  <pre><code>@property (strong, nonatomic) NSArray * myArray;
  </code></pre>
  
  <p>A method to return a number of objects in <code>myArray</code> would look like:</p>
  
  <pre><code>- (NSInteger) numberOfObjectsInMyArray
  {
      return [self.myArray count];
  }
  </code></pre>
  
  <p>This would return either the number of objects in the array, or 0 if <code>myArray == nil</code>;</p>
  
  <p>The best equivalent I can think of for doing this in Swift is:</p>
  
  <pre><code>var myArray: Array&lt;String&gt;?
  
  func numberOfObjectsInMyArray() -&gt; Int
  {
     return myArray ? myArray!.count : 0
  }
  </code></pre>
  
  <p>So checking the optional array contains a value, and if so unwrap the array and return that value, otherwise return 0.</p>
  
  <p>Is this the correct way to do this? Or is there something simpler?</p>