title: Expected Declaration error creating array in ViewController, can't work out why
body: <p>First, I am using Xcode 6 beta 2.  Second, I do have programming experience (basic, VB, script languages) ,but it doesnt include any serious OO programming, and I am totally new to IOS programming.   Going straight into Swift.  In advance, thanks to those who can help. I have been struggling over this a few days now. </p>
  
  <p>Having trouble building a simple UIImage array.  (I've stripped out all other code for simplicity.)  I'm trying to understand why declaring an UIImage array and loading images works within viewDidLoad(), but not at the "base" of ViewController, which is where I seem to need it for other things to work. </p>
  
  <p>(I've noticed it seems to be tied into the fact that this is an array declaration, which futhers my confusion.   I can declare and assign simple UIImage variables in either location.)</p>
  
  <p>Here's my code:</p>
  
  <pre><code>//  ViewController.swift
  
  
  import UIKit
  
  class ViewController: UIViewController {                           
  
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
          // Do any additional setup after loading the view, typically from a nib.
  
      }
  
  
  
      override func didReceiveMemoryWarning() {
  
          super.didReceiveMemoryWarning()
  
          // Dispose of any resources that can be recreated.
  
      }
  
      var icon = UIImage[]()
  
      icon.append(UIImage(named: "yes.png"))    &lt;&lt;==== expected declaration error
  
      icon.append(UIImage(named: "no.png"))
  
  }
  </code></pre>
  
  <p>But this code does not:</p>
  
  <pre><code>import UIKit
  class ViewController: UIViewController {
  
       override func viewDidLoad() {
  
          super.viewDidLoad()
  
          // Do any additional setup after loading the view, typically from a nib.
  
          var icon = UIImage[]()
  
          icon.append(UIImage(named: "yes.png"))    &lt;==== no error, and builds
  
          icon.append(UIImage(named: "no.png"))
  
      }
  
  
      override func didReceiveMemoryWarning() {
  
          super.didReceiveMemoryWarning()
  
          // Dispose of any resources that can be recreated.
  
      }
  
  }
  </code></pre>