1

In my iOS messaging app, I'd like to display a list of the newest messages a user have with his interlocutors. In other words, this view is an overview of all chats.

I found an answer for an SQL query that I've tried on the sqlite file:

SELECT m1.* FROM ZMMESSAGE m1 LEFT JOIN ZMMESSAGE m2 
ON (m1.ZINTERLOCUTORUSERNAME = m2.ZINTERLOCUTORUSERNAME AND m1.ZSENTAT < m2.ZSENTAT) 
WHERE m2.ZSENTAT IS NULL;

The query gives me the expected records, but how can I make an NSFetctRequest that does the same?

My entitiy is as follows:

enter image description here

Community
  • 1
  • 1
Andreas
  • 183
  • 1
  • 10
  • Can you add the definition of the Core Data entities, attributes and relationships to your question? – Martin R Nov 13 '12 at 14:50
  • I doubt that you can translate that query into a fetch request (but I may be wrong). - But wouldn't it make more sense to define a separate *User* entity (with name and imageid attributes) and a (one-to-many?) relationship from *User* to *Message*? – Martin R Nov 13 '12 at 17:35
  • @MartinR I could, but would that help? – Andreas Nov 13 '12 at 22:13
  • Fetching the latest message for each user should be possible (if that is what you need) – Martin R Nov 13 '12 at 22:16

0 Answers0