-
Notifications
You must be signed in to change notification settings - Fork 89
Support Array Of Fields For Custom Transformation #120
Conversation
5e1ce76
to
63c2d8c
Compare
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.
Tiny comments
Sources/Mapper.swift
Outdated
/// otherwise nil | ||
public func optionalFrom<T>(_ fields: [String], transformation: (Any) throws -> T?) -> T? { | ||
for field in fields { | ||
if let value = try? transformation((try self.JSONFromField(field))) { |
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.
remove extra parens?
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.
done
Sources/Mapper.swift
Outdated
if let value = try? transformation((try self.JSONFromField(field))) { | ||
return value | ||
} | ||
} |
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.
newline after
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.
done
Also please add a changelog entry |
} | ||
|
||
let test = try? Test(map: Mapper(JSON: ["a": "##", "b": 1])) | ||
XCTAssertNil(test?.value) |
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.
Can you adjust these tests to be like the ones above these new ones, we want to make sure that test
is non-nil, but value is, so we should catch the try
with an XCTFail
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.
done
added change log. |
Now I'll squash. |
Returns `nil` if key doesn't exist or transformation for found value throws.
6d12620
to
a38b607
Compare
Pushed 7.2.0 |
Returns
nil
if key doesn't exist or transformation for found value throws.