Appending list objects to realm swift


#1

cannot append all objects to list in realm model .out of 12 objects only 4 are getting appended to realm db


#2

Can you show a sample of the code you use to append the objects to the List?

Are you using List.Append() (https://realm.io/docs/swift/3.1.1/api/Classes/List.html#/s:FC10RealmSwift4List6appendFxT_)?


#3

if(!(response[“branchProducts”] is NSNull)){
for bpDict in response[“branchProducts”] as! [Any]{
let bpr = bpDict as![String:Any]
var bp = RealmBranchProduct()
bp = self.branchProductParser(response: bpr)
if(!(self.branchProducts.contains(where: {$0.id == bp.id}))){
self.branchProducts.append(bp)
}
}
}

above is the code that i use for parsing response from api to realm model .
the line ‘‘self.branchProducts.append(bp)’’ is not appending all objects . at the time of creating realm model .However when i added the object “bp” to realm before appending to list “self.branchProducts” its working i.e

try! Constants.realm.write {
Constants.realm.add(bp, update: true)
}
self.branchProducts.append(bp)

.It sounds weird . same kind of issue appears everywhere .it would be helpful if you can provide me an exact approach to append list objects while adding model to realm