Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Support Array Of Fields For Custom Transformation #120

Merged
merged 1 commit into from
Oct 6, 2017

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Oct 5, 2017

Returns nil if key doesn't exist or transformation for found value throws.

@dduan dduan force-pushed the array_transformation branch from 5e1ce76 to 63c2d8c Compare October 5, 2017 03:18
@dduan
Copy link
Contributor Author

dduan commented Oct 5, 2017

@keith

Copy link
Contributor

@keith keith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comments

/// 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))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra parens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if let value = try? transformation((try self.JSONFromField(field))) {
return value
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline after

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@keith
Copy link
Contributor

keith commented Oct 6, 2017

Also please add a changelog entry

}

let test = try? Test(map: Mapper(JSON: ["a": "##", "b": 1]))
XCTAssertNil(test?.value)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@dduan
Copy link
Contributor Author

dduan commented Oct 6, 2017

added change log.

@dduan
Copy link
Contributor Author

dduan commented Oct 6, 2017

Now I'll squash.

Returns `nil` if key doesn't exist or transformation for found value throws.
@dduan dduan force-pushed the array_transformation branch from 6d12620 to a38b607 Compare October 6, 2017 06:46
@keith keith merged commit e3f6c09 into lyft:master Oct 6, 2017
@dduan dduan deleted the array_transformation branch October 6, 2017 06:54
@keith
Copy link
Contributor

keith commented Oct 6, 2017

Pushed 7.2.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants