Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1040685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:15:17+00:00 2026-05-16T15:15:17+00:00

How would I do the equivalent of this statement in Core Data? Basically I

  • 0

How would I do the equivalent of this statement in Core Data? Basically I want to get a list of the 10 most occurrences of foo along w/ how many times it occurs.

Basically I’m recording all of my users searches as individual entries in Core Data. I want to be able to select their 10 most searched items and display them in order starting w/ the most popular. So basically I want something like:


  • Baa | 10
  • Sea | 8
  • Box | 6

etc…..


Thanks for any help you can provide. I’m still new to Core Data.

  SELECT foo,
         COUNT(foo) AS occurances 
    FROM bar 
GROUP BY foo 
ORDER BY occurances DESC 
   LIMIT 10;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:15:18+00:00Added an answer on May 16, 2026 at 3:15 pm

    First, create a Core Data Entity that has: userSearchTerm and userSearchDate. And create a record everytime a search is done.

    Start the code by declaring the fetch request.
    And use NSPredicate to filter by date:

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"UserSearches" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
    
    NSPredicate *nameFilter = [NSPredicate predicateWithFormat:@"(userSearchDate like[cd] %@) AND (userSearchTerm like[cd] %@)",weekName,termToFind];
    [fetchRequest setPredicate:nameFilter];
    

    The [cd] in the like filter specifies it’s not case-sensitive. You may also need to change this filter depending on the date and format you want to use

    Then, set the fetchResultType as NSDictionaryResultType:

    [fetchRequest setResultType:NSDictionaryResultType];
    

    This will return a dictionary which you can use.

    To use aggregate functions you need to use NSExpressionDescription

    This is an extensive code and I’m not able to test it correctly for you, but you can read it here. On section Fetching Specific Values, it describes how to do the aggregate functions:
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html

    For a reference of all the available aggregate functions for NSExpression go to function expressionForFunction:arguments: where the list is located.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to convert this SQL statement to a JPQL equivalent. SELECT *
I'm looking for the equivalent of what in js would be 'this is a
I would like to do the equivalent of chmod -w+r-x foo or attrib +R
To this SO question: What is the C# equivalent of friend? , I would
I need the equivalent of this SQL statement in Linq, using method/fluent syntax. SELECT
I have the folowwing statement and I would like to have a LINQ equivalent:
What would be equivalent of Number(4) of Oracle database to MySQL Datatype ?
What would be C# equivalent? private array<__int32>^ func() { }
What would be the windows (command prompt) equivalent of the following command? find -cmin
How would I execute a query equivalent to select top 10 in couch db?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.