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 1045519
In Process

The Archive Base Latest Questions

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

I am building a social app that has a chatView. Message is an entity.

  • 0

I am building a social app that has a chatView. Message is an entity. On the usersViewController (rootViewController), I want to just display the number of unread messages from each user. But on the chatView, I want to show the messages sent between me and the selected user.

How should I fetch the messages from Core Data?

  1. Is there a way to fetch them all into an NSMutableDictionary with userIds as keys, each pointing to an NSMutableArray of Message entities? Or, would I have to fetch all the Messages and then iterate through them with Objective-C to arrange them as described?

  2. Either way, should I load them all upfront in the appDelegate? Or, should I only load the messages for the specific conversation upon viewing the corresponding chatView?

  3. To get the unread counts, should I iterate through the fetched Message entities to make an NSMutableDictionary of userID keys pointing to count values? Or, should I make a predicate that acts like a SQL sum query grouped by userId (Is that even possible with Core Data?)?

  4. Should I create a model, call it UnreadMessageCount, that stores the number of unread messages that I have from each user and a reference to the User model? I want to have all the unread messages on the first page of the app, so this would make that query faster. But receiving messages would be slower because I would not only have to add it to the Message model but also I would have to increment the count for that user in the UnreadMessageCount model. Also, the data would sort of be duplicated. Also, I’ll only make the query for all message counts once per application launch, but i’ll make queries to update the unread message count every time I receive a new message and am not on the chatView page with that user.

Please fill me in on iPhone memory management & Core Data possibilites and performance. And also please give your opinion on the best way to engineer this.

Thanks!

Matt

  • 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:59:52+00:00Added an answer on May 16, 2026 at 3:59 pm

    To get the message count, I would ask the managed object context for the count of messages given a certain fetch request, for example, to count the messages for a certain user:

    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
    
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Message" inManagedObjectContext:context];
    [request setEntity:entity];
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user == %@", user];
    [request setPredicate:predicate];
    
    NSInteger count = [context countForFetchRequest:request error:nil];
    

    Here I’m assuming that the Message entity has a user relationship.

    To get the actual messages for that same user, I would just replace the last line for:

    NSArray *messages = [context executeFetchRequest:request error:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a small local social good community website where every project has his
I am in the process of building a site that will contain features comparable
I'm developing a niche social networking site that is going multilingual. That means our
I have been building applications / web apps for some time, and I guess
I'm building the data model for the website of a student club at my
I was wondering what the best practices were for building and storing IDs. A
Hey all, brand new to asp.net mvc and I am creating a fake social
I've got a repeated code block that initializes a few variables in a bunch
I have three pages 1) index.aspx 2) schools.aspx 3) Classes.aspx All the pages has
I'm working with a WCF service in Azure, which uses Windows Live ID authentication

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.