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

  • Home
  • SEARCH
  • 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 8267137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:24:27+00:00 2026-06-08T05:24:27+00:00

I have the following objects in my chat app (with one-to-many relationship) @interface ChatEntry

  • 0

I have the following objects in my chat app (with one-to-many relationship)

@interface ChatEntry : NSManagedObject
@property (nonatomic, retain) NSString * text;
@property (nonatomic, retain) NSDate * timestamp;
@property (nonatomic, retain) ChatContext *context;
@end

@interface ChatContext : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * userId;
@property (nonatomic, retain) NSSet *entries;
@end

Each conversation (ChatContext) groups all messages send by this user (uniquely identified by userId field).

I’m trying to display a list of conversations which displays the last message of each conversation (similar to iMessage).

I’m using the following code:

NSFetchRequest* request=[[NSFetchRequest alloc] initWithEntityName:@"ChatEntry"];
request.predicate=[NSPredicate predicateWithFormat:@"timestamp=context.entries.@max.timestamp"];
request.sortDescriptors=[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO]];
m_chat=[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:m_context sectionNameKeyPath:nil cacheName:@"chat"];
m_chat.delegate=self;

This works fine until I receive a new message (with NSFetchedResultsChangeInsert)

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
...
}

At that point, I get ANOTHER entry in my table view. The fetch controller keeps the previous entry (even though its timestamp is not the latest one anymore). I’m not sure how to solve this and force the controller to always evaluate the predicate.

Alternatively, I’ve tried to change my query to fetch ChatContext instances, but then I’m not sure how to actually read the latest entry in that context.

  • 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-06-08T05:24:28+00:00Added an answer on June 8, 2026 at 5:24 am

    OK, I’ve managed to solve that. What I did is to add a “lastMessage” object to the context, which I keep updating on every new message. I then query the list of contexts, sorted by reversed lastMessage.timestamp. New messages update the lastMessage property in their context – which triggers an event and update the UI automatically.

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

Sidebar

Related Questions

I have the following class objects in Google App Engine's dadastore, I can see
I have the following app, that's like a chat, so I'm programmatically creating some
Suppose I have the following objects (one table per object) with this relations: A
I have the following array of objects which I need to convert to one
I have two objects: Poll and PollIp (one-to-many). I want to select all polls
I have following nested objects. I am using @Valid for validation in my controller.
I have the following objects: @JsonFilter(myFilter) public class Person { private Name name; private
I have the following objects. An IEnumerable <Agency > Agencies, which then contains BusinessUnits
I currently have the following objects persisting successfully: Person first name, etc. Exams title,
I have the following domain objects: public class UserSpecialization : PersonSpecialization, IUserSpecialization { public

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.