Swift 3 XMPP框架在XMPPMessageArchiving_Message_CoreDataObject中正确使用了willInsert()和didUpdate()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Swift 3 XMPP框架在XMPPMessageArchiving_Message_CoreDataObject中正确使用了willInsert()和didUpdate()相关的知识,希望对你有一定的参考价值。

XMPPMessageArchiving_Message_CoreDataObject class

import UIKit

open class XMPPMessageArchiving_Message_CoreDataObject : NSManagedObject {
   open var message: XMPPMessage! // Transient (proper type, not on disk)

   open var messageStr: String! // Shadow (binary data, written to disk)


   /**
    * This is the bare jid of the person you're having the conversation with.
    * For example: robbiehanson@deusty.com
    * 
    * Regardless of whether the message was incoming or outgoing,
    * this will represent the "other" participant in the conversation.
   **/

    open var bareJid: XMPPJID! // Transient (proper type, not on disk)

    open var bareJidStr: String! // Shadow (binary data, written to disk)


    open var body: String!

    open var thread: String!


    open var outgoing: NSNumber! // Use isOutgoing

    open var isOutgoing: Bool // Convenience property


    open var composing: NSNumber! // Use isComposing

    open var isComposing: Bool // Convenience property


    open var timestamp: Date!


    open var streamBareJidStr: String!


    /**
     * This method is called immediately before the object is inserted into the managedObjectContext.
     * At this point, all normal properties have been set.
     * 
     * If you extend XMPPMessageArchiving_Message_CoreDataObject,
     * you can use this method as a hook to set your custom properties.
     **/
     open func willInsert()


    /**
      * This method is called immediately after the message has been changed.
      * At this point, all normal properties have been updated.
      * 
      * If you extend XMPPMessageArchiving_Message_CoreDataObject,
      * you can use this method as a hook to set your custom properties.
      **/
      open func didUpdate()

}

嗨,

我是Swift 3和XMPPframework的新手,我正在尝试在XMPPMessageArchiving_Message数据模型的核心数据中添加新列,它为我的用例记录了额外的数据,在类中声明需要扩展以添加自定义属性。似乎课程的扩展对我不起作用。下面是测试willInsert()的示例扩展块

willInsert Test

extension XMPPMessageArchiving_Contact_CoreDataObject {

    open func willInsert(){
        print("In willInsert()")
        //to-do additional data
    }

}

这是在课堂上调用钩子提及的正确方法吗?

在此先感谢您的回复..

答案

对于这种情况,我做了类的扩展和overrideXMPPMessageArchiving_Contact_CoreDataObject如下

    extension XMPPMessageArchiving_Contact_CoreDataObject{
      open override func willSave(){

       \Your code here before you insert

      }
    }

以上是关于Swift 3 XMPP框架在XMPPMessageArchiving_Message_CoreDataObject中正确使用了willInsert()和didUpdate()的主要内容,如果未能解决你的问题,请参考以下文章

6. Swift 基于Xmpp和openfire实现一个简单的登录注册

在swift 3中无法连接到xmpp中的套接字

在 Swift 3.0 中使用 XMPP 阻止和取消阻止用户

使用 iOS 和 Swift 3 在委托方法中未接收到 xmpp 存在

在 Swift 中请求服务器接收 xmpp 消息

IOS XMPP(即时通讯的框架)