Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property mapping is not called #266

Open
amgadserry opened this issue Feb 3, 2018 · 2 comments
Open

Property mapping is not called #266

amgadserry opened this issue Feb 3, 2018 · 2 comments

Comments

@amgadserry
Copy link

amgadserry commented Feb 3, 2018


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

@amgadserry
Copy link
Author

amgadserry commented Feb 3, 2018

    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

@evermeer
Copy link
Owner

evermeer commented Feb 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants