Closed Busta117 closed 5 years ago
using this https://gist.github.com/Busta117/78a1aded0a73cf1c4f61bfda113a86c8 is no needed the ListTransform and no need to care about context
care to develop on the usage @Busta117 ? I'm also curious on how I can get more context out of List
mapping
@danipralea adding that file (link i posted) to your project and in the method mapping
just use it like any other mapping
func mapping(map: Map) {
variableList <- map["keyOnJson"]
}
thanks @Busta117 for your reply. I meant can I have any information that a child is being mapped inside a list vs. mapping on its own?
@danipralea i don't understand your question, every child/element on a list is mapping in the same way, go thru the method mapping
of the every child and it will mapping it, you can just put a breakpoint on the mapping
method of the child and you will see that it is mapped... object mapper get an array from the json response, this method(link) just convert that array of elements into a realm list to allow it to save it on the database
As of v0.9
, you may use the onSerialize
method to control whatever context you would like:
class User: Object, Mappable {
func mapping(map: Map) {
username <- map["username"]
friends <- (map["friends"], ListTransform<User>(onSerialize: onSerialize))
}
private func onSerialize(users: List<User>) {
let realm = Storage.shared.realm
try! realm.write {
realm.add(users, update: .modified)
}
}
}
there is no way to send a context to the List Transform...