evermeer / EVReflection

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Other
965 stars 119 forks source link

EVReflectable reports "does not conform to protocol" #184

Closed biomiker closed 7 years ago

biomiker commented 7 years ago

I apologize for what I imagine is a naive question (and thank you for an amazing library!), but looking at the https://github.com/evermeer/EVReflection#extending-existing-objects I used the following:

extension MKPolygon: EVReflectable { }

The compiler complains: "Type 'MKPolygon' does not conform to protocol 'EVReflectable'"

I imagine this is not an issue, or perhaps with documentation only? In any case, is there a way to make MKPolygon EVReflectable? Thanks!!!

biomiker commented 7 years ago

Hmmm, I see now that I should have been looking at https://github.com/evermeer/EVReflection#custom-type-converter

It might be worthwhile to update the docs to put combine these two sections with an explanation of how to determine when EVReflectable is sufficient and when EVCustomReflectable becomes necessary.

More importantly however, it doesn't seem to work. The compiler now complains:

Use of undeclared type EVCustomReflectable

Any thoughts? I have imported EVReflection of course and my EVObject is working. Thanks!!!

Update, I installed via CocoaPods, and do notice that the only file in Source is EVReflection.swift ...

evermeer commented 7 years ago

Hi,

What version of EVReflection do you have active? I think That in version 4.7 I had a bug where I added a function to the EVReflecable protocol without adding a default implementation. Because of that you would get that 'does not conform...' message since you need that function. With the latest version you should just be able to extend any class that inherits from NSObject. This compiles:

class MKPolygon: NSObject { }
extension MKPolygon: EVReflectable { }

EVCustomReflectable was added in version 4.8. So when you get the message that it's unavailable, then I do think that you are getting an older version. When you look in your pods project in the EVRelection folder, then indeed you should see 6 files that start with EV

evermeer commented 7 years ago

O, MKPolygon is from mapkit isn't it? I think that you are right that you then should use the EVCustomReflectable.

biomiker commented 7 years ago

First off, I only had v 4.5.0. I installed earlier today from Podfile using "pod EVReflection" but pod update did update to 4.8.1. Why it didn't just install that in the first place? Anyway, thanks!

MKPolygon is from MapKit but it also inherits from NSObject so I thought that EVReflectable perhaps would work. I'll poke around now that I'm on the right version. Thanks again!

evermeer commented 7 years ago

If NSObject is the base class, then EVReflectable could work. Just use EVCustomReflectable if the mismatch between MKPolygon and your json is too large.