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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:01:00+00:00 2026-06-02T00:01:00+00:00

This has to be a common question and I found many related here in

  • 0

This has to be a common question and I found many related here in SO, but none with the solution for this.

I have these 2 coredata models:

@class Message;
@interface Conversation : NSManagedObject
@property (nonatomic, retain) NSString * number;
@property (nonatomic, retain) NSSet *messages;
@property (nonatomic, retain) Message *lastMessage;

And

@class Conversation;
@interface Message : NSManagedObject
@property (nonatomic, retain) NSString * account;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSString * message;
@property (nonatomic, retain) NSNumber * sentFlag;
@property (nonatomic, retain) NSString * status;
@property (nonatomic, retain) Conversation *conversation;

In my ConversationListViewController I fetch all conversations ordered by lastMessage.date.
Then the ConversationViewController receives a Conversationand lists its messages.

Right now I’m handling lastMessage manually, so every time I add a new message, in ConversationViewController, I also update conversation.lastMessage.
Is there a better way to do it?
Because right now, there’s only one place I insert/update a new message, but if there was something like insert/update triggers that’d sound better..

I know I could fetch all Conversations and then sort them with a sortdescriptor using messages.@max.date but that doesn’t sound like a good solution for a large pool of messages/conversations.

  • 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-02T00:01:02+00:00Added an answer on June 2, 2026 at 12:01 am

    I really don’t think that there is something more elegant or any kind of better way, then setting newMessage.conversation.lastMessage = newMessage.
    Core Data posts notifications, every time it adds or changes an entity, but i don’t think,that it would be easier to observe them, then adding this line of code every time you create a new message.

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

Sidebar

Related Questions

This is probably a common question, but all answers on the internt have failed
I'm sure this must be a common question, but I haven't found an answer
I know this question has been asked many times here and elsewhere before as
This has to be a common question that all programmers have from time to
I feel like this is a common problem but nothing I've researched has worked
This has to be a frequent question, but not on SO yet, so it
Looked for an answer for this question, but I haven't found a suitable one
I think this question is quite common. Recently I have got a requirement that
I know this is a common question topic. However I haven't found an answer
I am sure that this must be a pretty common question but after scouring

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.