我坚持将以上所有内容放在一起。如果能得到任何输入,我将不胜感激。
这是我的简短设置:
typealias RealmObject = Object
/// Extension to ignore undefined keys when mapping
extension RealmObject : EVReflectable {
open override func setValue(_ value: Any?, forUndefinedKey key: String) { }
}
领域示例模型:
class Product: RealmObject {
dynamic var productId: String = ""
let productLanguages = List<ProductLanguage>()
override static func primaryKey() -> String? {
return "productId"
}
}
class ProductLanguage: RealmObject {
dynamic var productLanguageId: String = ""
dynamic var languageCode: String = ""
dynamic var productName: String = ""
override static func primaryKey() -> String? {
return "productLanguageId"
}
}
要获取产品详细信息,请使用Moya和RxSwift:
func getProduct(productItemKey: String) -> Observable<Product> {
return provider.request(.product(productId: productItemKey)).map(to: Product.self)
}
我认为
.map(to: Product.self)
不适用于开箱即用的领域列表。对于列表中的每个对象,我都会收到一个错误:ERROR: Could not create an instance for type
dict:{
CreateDate = "2015-10-12T11:11:50.013Z";
IngredientList = "Acao ingredient";
LanguageCode = "en-US";
ProductId = "d6bb0084-6838-11e5-9225-00ac14ef2300";
ProductLanguageId = "f96848d0-df77-4594-99b7-d390bb127891";
ProductName = Acao;
Tagline = "The smart drink - 100% organic, vegan energy booster with guara"
}
还有其他方法可以将Moya响应映射到Realm对象吗?
非常感谢您的投入!
最佳答案
原来这是EVReflection中的错误。在4.17.0中修复
关于ios - EVReflection + Moya + Realm + RxSwift-无法为dict类型创建实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45191727/