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

PropertyMapping doesn't work with Realm #296

Open
Daedren opened this issue Oct 19, 2018 · 0 comments
Open

PropertyMapping doesn't work with Realm #296

Daedren opened this issue Oct 19, 2018 · 0 comments

Comments

@Daedren
Copy link

Daedren commented Oct 19, 2018

I've been using EVReflection with Alamofire, Moya and RxSwift with absolutely no issues. An excerpt of the Podfile is as follows:

pod 'Alamofire'
pod 'RxSwift'
pod 'Moya/RxSwift'
pod 'EVReflection/MoyaRxSwift'

Now I've been giving Realm a try, and I've been having numerous issues. Essentially, JSONs with pascal case are no longer automatically mapped to camel case variables. I've also tried adding the propertyMapping function but it's ignored.

The added pods are:

pod 'EVReflection/Realm'
pod 'RealmSwift'

And an example model would be:

import Foundation
import EVReflection
import RealmSwift

public class Transaction: Object, EVReflectable {
    @objc public dynamic var operationCode: String?
    @objc public dynamic var streamId: String?

    public func propertyMapping() -> [(keyInObject: String?, keyInResource: String?)] {
        return [(keyInObject: "operationCode", keyInResource: "OperationCode")]
}

A network call that maps this would for example be

    public func getTransaction(streamId:String, onNext: @escaping ((Transaction) -> Void), onError: @escaping ((Moya.MoyaError?)-> Void)) -> Void {
        Network
            .accountProvider.rx
            .request(AccountTarget.getTransaction(for: streamId).asObservable()
            .Rmap(to:Transaction.self)
            .observeOn(MainScheduler.instance)
            .subscribe(
                onNext: onNext,
                onError: onError,
                onCompleted:nil,
                onDisposed:nil)
            .disposed(by:Network.disposeBag)
}
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

1 participant