-
Notifications
You must be signed in to change notification settings - Fork 4
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
Marshal mapping #3
Conversation
# Conflicts: # Example/ACKReactiveExtensions.xcodeproj/project.pbxproj # Example/Podfile.lock # Example/Pods/Manifest.lock # Example/Pods/Pods.xcodeproj/project.pbxproj # Example/Pods/Target Support Files/Pods-ACKReactiveExtensions_Example-ACKReactiveExtensions_Tests/Pods-ACKReactiveExtensions_Example-ACKReactiveExtensions_Tests.debug.xcconfig # Example/Pods/Target Support Files/Pods-ACKReactiveExtensions_Example-ACKReactiveExtensions_Tests/Pods-ACKReactiveExtensions_Example-ACKReactiveExtensions_Tests.release.xcconfig # README.md
Conflicts resolved |
} | ||
else if let marshaledArray = json as? [MarshaledObject] { | ||
let dummyKey = "dummyKey" | ||
return try [dummyKey: marshaledArray].value(for: dummyKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try marshaledArray.map (Model.init)
} | ||
|
||
extension MarshalError: MarshalErrorCreatable { | ||
public static func createMarshalError(_ marshalError: MarshalError) -> MarshalError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be _ marshalError: NSError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any reason why? As far as Marshal is throwing MarshalError
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaaa I see...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now when all errors thrown by the extension are really MarshalError
s this is correct.
guard let marshaledJSON = json as? MarshaledObject | ||
else { | ||
assertionFailure("json isn't any of the known MarshaledObject types (Dictionary or Array)") | ||
throw NSError(domain: "", code: 0, userInfo: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get rid of this and throw some better error?
* | ||
* - parameter key: If your objects are contained within dictionary pass the key here | ||
*/ | ||
public func mapResponseMarshal<Model>(for key: KeyType? = nil) -> SignalProducer<Model, Error> where Model: Unmarshaling { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change it to forKey key: KeyType? = nil)
. It's not clear what for: means.
public func mapResponseMarshal<Model>(for key: KeyType) -> SignalProducer<Model, Error> where Model: ValueType { | ||
return lift { $0.mapResponseMarshal(for: key) } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be also nice to have some test to call the public API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean something like this?
Introduce
mapResponseMarshal
extension forSignalProducer
.