I have an entity in which i have some attributes to which I have pass custom class which store data in an array of that class My core data entity looks like this,
My NSManangedObject
Class looks like this,
extension SingleChat {
@nonobjc public class func fetchRequest() -> NSFetchRequest<SingleChat> {
return NSFetchRequest<SingleChat>(entityName: "SingleChat")
}
@NSManaged public var name: String?
@NSManaged public var roomSID: String?
@NSManaged public var isGroup: Bool
@NSManaged public var lastMessage: String?
@NSManaged public var lastMsgTime: String?
@NSManaged public var lastMsgTimeActual: String?
@NSManaged public var profilePic: String?
@NSManaged public var lastMsgRead: Bool
@NSManaged public var unReadMsgsCount: Int16
@NSManaged public var actualNameFor_1_2_1_chat: String?
@NSManaged public var isNewGroup: Bool
@NSManaged public var members : [TCHMember]
@NSManaged public var messages : [TCHMessage]
@NSManaged public var twChannelObj: TCHChannel?
@NSManaged public var groupInfo : [String:JSON]?
}
This is how i save my data in core data ,
let appDelegate = UIApplication.shared.delegate as? AppDelegate
let context = appDelegate?.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "SingleChat", in: context!)
let user = NSManagedObject(entity: entity!, insertInto: context)
for items in dateWiseSortedSingleRooms
{
user.setValue(items.name, forKey: "name")
user.setValue(items.actualNameFor_1_2_1_chat, forKey: "actualNameFor_1_2_1_chat")
user.setValue(items.isGroup, forKey: "isGroup")
user.setValue(items.lastMsgRead, forKey: "lastMsgRead")
user.setValue(items.lastMsgTimeActual, forKey: "lastMsgTimeActual")
user.setValue(items.lastMessage, forKey: "lastMessage")
user.setValue(items.lastMsgTime, forKey: "lastMsgTime")
user.setValue(items.profilePic, forKey: "profilePic")
user.setValue(items.roomSID, forKey: "roomSID")
user.setValue(items.isNewGroup, forKey: "isNewGroup")
user.setValue(items.unReadMsgsCount, forKey: "unReadMsgsCount")
user.setValue(items.unReadMsgsCount, forKey: "unReadMsgsCount")
user.setValue(items.members, forKey: "members")
user.setValue(items.messages, forKey: "messages")
user.setValue(items.twChannelObj, forKey: "twChannelObj")
}
do {
try context?.save()
print("Saved successfully.")
} catch {
print("Fail to save")
}
Now when my code execute app crashes at this line,
user.setValue(items.members, forKey: "members")
user.setValue(items.messages, forKey: "messages")
With error this,
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TCHMember encodeWithCoder:]: unrecognized selector sent to instance 0x2807a1780
How I can resolve this? and store my custom class array data in it?