How do I check if a variable is declared in Swift?
<p>I know that if a variable is declared it is easy to test whether or not it is null, but I can't find a way to work out if a variable is declared at all. What I need is:</p>

<p>If variable is declared:</p>

<pre><code>var i:Int
if [i is declared] {
  // returns true
}
</code></pre>

<p>If variable is not declared:</p>

<pre><code>if [i is declared] {
   // returns false (but does not crash)
}
</code></pre>

<p>Use case: I am writing an app to teach people Swift. I want to be able to evaluate their code and make sure it is correct. So my instruction might be 'create a variable called i and set it equal to 1' and I want to test if they have done that correctly. In PHP I can do isset($i), I need an equivalent in Swift. I can't use if i == null because as simpleBob says that will crash if is not defined. </p>

<p>Thanks in advance!</p>

<p>Rob</p>