title: How to define static constant in a class in swift
body: <p>I have these definition in my function which work</p>
  
  <pre><code>class MyClass {
      func myFunc() {
          let testStr = "test"
          let testStrLen = countElements(testStr)
      }
  }
  </code></pre>
  
  <p>But if I move 'testStr' and 'testStrLen' to the class level, it won't compile. It said 'MyClass.Type does not have a member named 'testStr'. </p>
  
  <pre><code>class MyClass {
      let testStr = "test"
      let testStrLen = countElements(testStr)
  
      func myFunc() {
  
      }
  }
  </code></pre>
  
  <p>How can I fix this? I don't want to pay the penalty for counting len of a constant 'test' everytime.</p>
  
  <p>Based on my understanding of the comments below, I need to do this:</p>
  
  <pre><code>class MyClass {
      let testStr = "test"
      let testStrLen = countElements("test")
  
      func myFunc() {
  
      }
  }
  </code></pre>
  
  <p>Is there a way I don't need to type/enter "test" twice? 
  Thanks.</p>