From ca4235caa7703cc2da4761a5f02431f1ba87c8bb Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 27 Mar 2015 13:26:58 +0800 Subject: [PATCH] tryGetOrCreateMe do not in outer `beginWriteTransaction` `commitWriteTransaction` --- Yep/Services/YepService.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 6179a4fd..42f09da7 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -514,17 +514,18 @@ func sendText(text: String, toRecipient recipientID: String, #recipientType: Str message.mediaType = MessageMediaType.Text.rawValue message.textContent = text - // 消息来自于自己 - - if let me = tryGetOrCreateMe() { - message.fromFriend = me - } - realm.addObject(message) realm.commitWriteTransaction() + // 消息来自于自己 + + if let me = tryGetOrCreateMe() { + realm.beginWriteTransaction() + message.fromFriend = me + realm.commitWriteTransaction() + } // 消息的 Conversation,没有就创建