這是一個常見問題,我在這裏發現了許多相關的問題,但沒有解決這個問題。消息應用程序 - 對話lastMessage
我有這2款coredata:
@class Message;
@interface Conversation : NSManagedObject
@property (nonatomic, retain) NSString * number;
@property (nonatomic, retain) NSSet *messages;
@property (nonatomic, retain) Message *lastMessage;
而且
@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;
在我ConversationListViewController
我獲取由lastMessage.date
下令所有對話。
然後ConversationViewController
收到Conversation
並列出它的messages
。
現在我手動處理lastMessage
,所以每次我在ConversationViewController中添加一條新消息時,我也會更新conversation.lastMessage
。
有沒有更好的方法來做到這一點?
因爲現在,只有一個地方我插入/更新新的消息,但如果有類似的插入/更新觸發會更好的聲音..
我知道我可以獲取所有對話,然後對其進行排序使用[email protected]
的分類描述符,但對於大量消息/對話池來說聽起來不太合適。
我想這是有道理的。如果代碼多一點,也許可能有一個singleton觀察所有這些通知並進行更改(類似_trigger_),但在這種情況下聽起來有些開銷! – 2012-04-16 17:06:11