title: How to write NSPredicate Custom Object (CGFloat var) BETWEEN operation
body: <p>I want to do <strong>Number comparison</strong> using <strong>BETWEEN</strong> through <em>my custom object.</em>
  I have done string comparison, however Number comparison shouts error as in the code below.</p>
  
  <pre><code>class CustomClass: NSObject {
      var name        : String?
      var aWidth      : CGFloat!
  }
  </code></pre>
  
  <p>String comparison which works</p>
  
  <pre><code>let predicate = NSPredicate(format: "SELF.name contains[c] %@","Sal")
  </code></pre>
  
  <p>HOWEVER</p>
  
  <pre><code>let predicate = NSPredicate(format: "SELF.aWidth &gt; 0 AND SELF.aWidth &lt; 50")
  
  let predicate = NSPredicate(format: "SELF.aWidth &lt; 50")
  </code></pre>
  
  <p>This one totaly wrong I know. </p>
  
  <pre><code>let predicate = NSPredicate(format: "SELF.aWidth BETWEEN {%@, %@}", {minWidth, maxWidth})
  </code></pre>
  
  <blockquote>
    <p>reason: '[&lt;test.CustomClass 0x7fe86274bfd0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key <strong>aWidth</strong>.'</p>
  </blockquote>
  
  <p>All the search of this error took me storyboard questions.</p>
  
  <p>How can I write a predicate using BETWEEN?
  Thanks in advance</p>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>I also found this example about using <strong>filter in swift</strong> which is helpful. But I still have the problem.</p>
  
  <pre><code>class Person : NSObject {
  
      var age : CGFloat?
  
      init(age: CGFloat) {
          self.age = age
      }
  }
  </code></pre>
  
  <p><strong>Filter</strong></p>
  
  <pre><code>let eventAttendees = [Person(age: 22), Person(age: 41), Person(age: 23), Person(age: 30)]
                  let filteredAttendees = eventAttendees.filter({
                      $0.age &lt; 30
                  })
  
                  for person in filteredAttendees {
                      print(person.age!)
                      }
  </code></pre>
  
  <p>When I try to use same technique, I get this <strong>error</strong> this time.</p>
  
  <p><strong>First approach</strong></p>
  
  <pre><code>let array = self.testDictionary.allValues as Array
  
  var filteredArray = array.filter( { (user: Person) -&gt; Bool in
  
                      return $0.age &lt; 30
                  })
  </code></pre>
  
  <blockquote>
    <p>Anonymous closure arguments cannot be used inside a closure that has
    explicit arguments</p>
  </blockquote>
  
  <p><strong>Second Approach</strong></p>
  
  <pre><code>let array = self.testDictionary.allValues as Array
  
  var filteredArray = array.filter( { (user: Person) -&gt; Bool in
  
                          return true
                      })
  </code></pre>
  
  <blockquote>
    <p>Cannot convert value of type '(Person)' -> Bool to expected argument
    type '(Anyobject)' -> Bool</p>
  </blockquote>
  
  <p>Thanks</p>