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

EVReflaction does not process booleans #307

Closed AviranAbady closed 5 years ago

AviranAbady commented 5 years ago

Hello, I seem to have a problem to parse boolean properties in responses when using EVReflection/Alamofire, other variable types are being processed successfully.

using Alamofire (4.8.2)
using EVReflection (5.10.1)

pod 'Alamofire'
pod 'EVReflection', '~> 5.10.1'
pod 'EVReflection/Alamofire'  
import Foundation
import EVReflection

class ProcessResponse: EVNetworkingObject {
    var process_id: String?
    var endManually: Bool?    // This variable will remain null
}

The following warning is printed to the log:

WARNING: The class 'ProcessResponse' is not key value coding-compliant for the key 'endManually' There is no support for optional type, array of optionals or enum properties. As a workaround you can implement the function 'setValue forUndefinedKey' for this. See the unit tests for more information

The request code:

var req = Alamofire.request(...)
req.responseObject { (response: DataResponse<T>) in
}

Running the http request using curl results in the following response body:

{
  "endManually": true,
  "process_id": "AWr4gTnwo-6Pm____"
}
evermeer commented 5 years ago

As you can see in the warning: 'There is no support for optional type' So there is indeed no support for optional bool (because of Swift limitation)

For more of these see: https://github.com/evermeer/EVReflection#known-issues

the easiest way to solve this is to change it to a non optional bool. If you do need an optional bool, then you need to implement the setValue forUndefinedKey

AviranAbady commented 5 years ago

thanks