Fetch Grouped Data from Core Data

I have data in a table of messages. These messages are some sort of chat messages. Now I want to fetch the data in form of conversations like this...

Let's suppose we have a,b,c,d,e,f and m users. m is for myself. Now there are messages having senders from a,b,c,d,e,f and m and same is for receiver. All of the messages has m as sender or receiver and one object from other users. Now I want the data to be grouped as..

Groupe A

All messages having messages sent to a or received from a

Groupe B

All messages having messages sent to b or received from b

Groupe C

All messages having messages sent to c or received from c

and so on....

Can any one suggest how I may do that. I've looked into some questions but couldn't find the answer. Any one there to help would be appreciable.


Using a Fetched Results Controller, you have to consider that some messages will be included more than once.

1) Fetch User entity, sort by name

2) Number of sections: fetchedObjects.count

3) Number of rows in section:

NSSet *allMessages = [user.receivedMessages setByAddingObjectsFromSet:user.sentMessages];
return allMessages.count;

4) Populate the cell:

NSSet *allMessages = [user.receivedMessages setByAddingObjectsFromSet:user.sentMessages];
NSArray *sorted = [allMessages sortedArrayUsingDescriptors:@[[NSSortDescriptor 
            sortDescriptorWithKey:@"message.topic" ascending:YES]]];
Message *m = sorted[indexPath.row];

This can be simplified by adding a transient property to Userthat returns the sorted allMessages. Please not that doing this directly in the datasource methods is not very efficient, I just put it here to illustrate the point.

You can use NSFetchedresultscontroller if is in viewController result. This Object contains a section and row in the result data

Need Your Help

Change background-color of elements within an iframe on hover

jquery css iframe background hover

How do I change the background-color of elements in an <iframe>? The <iframe> is in my domain. Here is the complete code (HTML, PHP and jQuery):

Unboxing modifies items collection

c# winforms unboxing

Having a problem with this Winforms project. Trying to use the SelectedIndexChanged event on a combBox that that was populated with the dictionary propList via:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.