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
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<XMPPUserCoreDataStorageObject>)
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!
Well, you are trying to send the message to an object that cannot respond to it.
Look at your exception log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString managedObjectContext]: unrecognized selector sent to instance 0x7fdf8c545e50'***
managedObjectContext
message has been sent to an instance of NSString
class.
Of course, it cannot respond to it and you are getting the crash.