Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting a simple NSpredicate - Logic Issue
    primarykey
    data
    text
    <p>I have a <code>Person</code> object. and this <code>person</code> object has the following attributes;</p> <pre><code>Name StartDate EndDate </code></pre> <p>I am saving this <code>Person</code> objects to an <code>array</code>. This array might contain more than <code>100 person</code> objects.</p> <p>The following is an example of <code>person</code> objects in that array;</p> <pre><code>John, Tue Feb 22, Thr Mar 30 Jack, Wed Mar 09, Fri Apr 21 Jack, Thu Mar 19, Fri Dec 20 Jack, Tue Jan 08, Fri Apr 26 etc.. </code></pre> <p>Now i need to will supply a date, say for example <code>Wed 29 Mar</code>, and i need to check if it's in the range of <code>StartDate</code> and <code>EndDate</code> in the array of <code>persons</code> object. How can i do this ? My working are as follows, but it doesn't work (It gives incorrect results)</p> <pre><code>NSPredicate *datePred = [NSPredicate predicateWithFormat:@"StartDate&gt;= %@ &amp;&amp; EndDate&lt;= %@",givenDate,givenDate]; resultArray = [arrayContainingAllPersonObjects filteredArrayUsingPredicate:datePred ]; </code></pre> <p>I also tried the following method, but it too gives incorrect results (which was taken off a SO post);</p> <pre><code>NSPredicate *greaterThanPredicate = [NSPredicate predicateWithFormat:@"StartDate&lt;= %@", providedDate"]; NSPredicate *lessThanPredicate = [NSPredicate predicateWithFormat:@"EndDate&gt;= %@", ProvidedDate"]; NSPredicate *betweenPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:greaterThanPredicate, lessThanPredicate, nil]]; </code></pre> <p>I have no clue as in what is causing this, Help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload