i'm new in using realm, i'm trying to save my api response in realm database. For that i read out there documents and started my work, I have created class of Objects in which a have my variables in which i want to save data now when i add data in realm app crashes with error, Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
. This is my class of Objects,
class SingleChatRealm: Object {
var actualNameFor_1_2_1_chat = ""
var isGroup : Bool = true
var isNewGroup : Bool = false
var lastMessage = ""
var lastMsgRead : Bool = false
var lastMsgTime = ""
var lastMsgTimeActual = ""
var name = ""
var profilePic = ""
var roomSID = ""
var unReadMsgsCount = 0
var twChannelObj : TCHChannel?
var members = [TCHMember]()
var messages = [TCHMessage]()
// @objc dynamic var group_info : [String:JSON]?
} and this is how i'm storing data in realm,
let realm = try! Realm()
try! realm.write {
let newListing = SingleChatRealm()
for items in dateWiseSortedSingleRooms
{
newListing.actualNameFor_1_2_1_chat = items.actualNameFor_1_2_1_chat
newListing.isGroup = items.isGroup
newListing.isNewGroup = items.isNewGroup
newListing.lastMessage = items.lastMessage
newListing.lastMsgRead = items.lastMsgRead
newListing.lastMsgTime = items.lastMsgTime
newListing.lastMsgTimeActual = items.lastMsgTimeActual
newListing.members = items.members
newListing.messages = items.messages
newListing.name = items.name
newListing.profilePic = items.profilePic!
newListing.roomSID = items.roomSID
newListing.twChannelObj = items.twChannelObj
newListing.unReadMsgsCount = items.unReadMsgsCount
print(newListing)
self.realm.add(newListing)
}
}
My app crashes on this line self.realm.add(newListing)
with above given error, why is it so? what's i'm missing in this?