I have an NSArray called message, it contains an unsorted list of custom objects. Every object has the same structure, it has an NSDictionary and two other string in it.
Every object is a message and i would like to sort them based on the dictionary key keySenderUser and keyReceiverUser. The new array should contain arrays, each array in the new array should represent the messages from a different user except the current user.
For example i have 50 message in the base message array, it contains messages from Bill, John, Anna, Taylor and the "current user". I would like to put every message into a new array where John is the keySenderUser or keyRecieverUser and put to a new mutable array where i collect the messages of the users and do the same with Bill, John, Anna and Taylor. The result should be an array that looks like this:
NSMutableArray *messagesFromUsers = @[messagesOfBill, messagesOfJohn, messagesOfAnna, messagesOfTaylor];
For example the messagesOfBill must contains the messages where Bill is the sender or the receiver that we know from the dictionary values. If Bill is the sender, current user is the receiver, if Bill is the receiver, current user is the sender. The other part always is the current user. There is no messages where Anna is the sender and Bill is the receiver.
As a first step i think i need a list with the usernames and then iterate through the all messages and create a new array for every user and collect these arrays into a new array, but honestly i don't have any idea how should i do it. I can remove objects from the message array based on one dictionary key, but that's all. I'm not experienced to figure it out alone.
UPDATE: This is how one object looks like in the message array:
NSLog(@"First message: %@", [message objectAtIndex:0]);
// result
First message: PNMessage (0x175d49f0): <message: {
keyCreateDate = \"06/08/14 21:23\";
keyMessage = "Lorem Ipsum ";
keyRecieverChannel = vidra;
keySenderUser = currentUsersName;
}, date: (null), channel: currentUsersName>
NSLog(@"First message: %@", [message objectAtIndex:0]);?