EVReflection
EVReflection copied to clipboard
Property mapping is not called
trafficstars
public class Address: EVManagedObject {
override public func propertyMapping() -> [(keyInObject: String?, keyInResource: String?)] {
return [
(keyInObject: "firstName",keyInResource: "first_name"),
(keyInObject: "lastName",keyInResource: "last_name"),
(keyInObject: "address1",keyInResource: "address_1"),
(keyInObject: "address2",keyInResource: "address_2")
]
}
func updateRemote(onSuccess: @escaping ()->(), onFailure: @escaping ()->()) throws{
if let user = User.current {
let url = "\(API.addressUrl)/\(user.id)"
let data: [String: Any] = self.toDictionary() as! [String : Any]
Alamofire.request(url, method: .post, parameters: data).validate().responseString(completionHandler: { response in
switch response.result {
case .success:
if let oldAddress = user.shippingAddress {
oldAddress.mr_deleteEntity(in: AppDelegate.getContext())
}
user.shippingAddress = self
try! AppDelegate.getContext().save()
onSuccess()
case .failure( _):
onFailure()
}
})
} else {
throw AddressErrors.noUserFound
}
}
}
self.toDictionary doesn't cause property mapping to be called
open func toDictionary(_ conversionOptions: ConversionOptions = .DefaultSerialize) -> NSDictionary {
let keys = Array(self.entity.attributesByName.keys)
return self.dictionaryWithValues(forKeys: keys) as NSDictionary
}
as I see here conversionOptions are ignored and the dictionaryWithValues used anyways @evermeer is that the intended behavior if not i could look into fixing it and make a PR
Ah, you are right, this is something I did not implement for CoreData. It would be awesome If you could make a pull request for this.