How to save and fetch in xmppGroupCoreDataStorageObject?

前端 未结 2 734
星月不相逢
星月不相逢 2021-01-27 00:54

Using xmpp-messenger-ios, I have created the group and set its configuration and adds the users into it, then I wants to add the group into the xmppGroupCoreD

2条回答
  •  [愿得一人]
    2021-01-27 01:22

    First of all, since you are saying that it crashes on the setValue for users line, one guess would be that your users set doesn't really contain objects of type XMPPUserCoreDataStorageObject (but it's supposed to). I think your method signature should be:

    public class func addUserInCoreData(jid: String, users: Set)
    

    Check the place where you call this function, it might be the case that you are passing a set of not XMPPUserCoreDataStorageObject objects, but some different type, which is wrong.

    But probably even more importantly:

    let entity = XMPPGroupCoreDataStorageObject.insertGroupName(jid, inManagedObjectContext: moc)
    

    should be called instead of

    let entity = NSEntityDescription.entityForName("XMPPGroupCoreDataStorageObject", inManagedObjectContext: moc!)

    and not after try moc?.save(). This method returns a XMPPGroupCoreDataStorageObject object that should be configured and then saved, not a bool indicating a successful save.

    Check out, for example, this tutorial (note the saveName method in the Saving to Core Data part): https://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial

    Good luck!

提交回复
热议问题