EVReflection
EVReflection copied to clipboard
PropertyMapping doesn't work with Realm
trafficstars
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)
}