Closed santhoshs5 closed 7 years ago
Realm does not persist dictionary types. You will need to use a List with a custom object that contains a property for the key and another List of Objects.
I have used List and and list transform but it does not help . Could you just help me with the code for the code snippet given.
@santhoshs5: instead of the dictionary, why don't you created another Object
that follows the [String:UserDevice]
data structure?
I solved it using List and transformOf
This is the below code
class UserInfo:Object,Mappable { var name:String? var identifier:String? var accountType:String? var devices:[String:UserDevice]? required init?(map: Map) {
}
// Mappable func mapping(map: Map) { name <- map["username"] identifier <- map["identifier"] accountType <- map["accountType"] devices <- map["devices"] } }
class UserDevice:Object,Mappable { var deviceName:String? var deviceType:String? var deviceIdentifier:String?
required init?(map: Map) {
}
// Mappable func mapping(map: Map) { deviceName <- map["name"] deviceType <- map["type"] deviceIdentifier <- map["identifier"] } }
this is my JSON:
{ username = santhosh; "identifier" = "IDJSDJSJS"; configstatus = SET; configtype = DEFAULT; "data_center" = "evs.idrive.com"; devices = { "Ankita\LKKKK" = { identifier = LJJDFDD; name = "Ankita iPAD"; type = iPad; }; "ARUN\LKKKHJH" = { identifier = LJJDFDFFD; name = "ARUN iPhone"; type = ipHone; };
accountStatus = 2; acctype = Test;