title: How to find maximum id which is integer in a given NSSet through NSPredicate in core data?
body: <p>I am using <code>core data</code>.I have two entities.one is session and second is scan.here is one to many relationship, means one session can have multiple scans.</p>
  
  <p>I have scans_id in scan Entity.Suppose in a session entity i have 3 scans means a <code>NSSet</code> of 3 scans.i want to find out that scan which is having maximum scans_id among the set.I want to do it from predicate.</p>
  
  <p>I am using this function.</p>
  
  <pre><code>-(void)CallForGetMaximumScanIDInSession:(Session *)ObjTempSession
  {
      NSSet *temp=ObjTempSession.scan;
      NSPredicate *predicate=[NSPredicate predicateWithFormat:@"scans_id==max(scans_id)"];
      NSSet *setTemp = [temp filteredSetUsingPredicate:predicate];
      NSArray *arrTemp=[setTemp allObjects];
  
      if (arrTemp.coun&gt;0 &amp;&amp; arrTemp.coun==1)
      {
          // arrTemp must having a single object of scan.
  
      }
  }
  </code></pre>
  
  <p>It is giving me crash on predicate line.</p>
  
  <p>Please let me know if i am making wrong predicate.</p>
  
  <p>Thanks in Advance.</p>