Generic materialize function with throwable behaviour for throwable initializers#890
Generic materialize function with throwable behaviour for throwable initializers#890iwheelbuy wants to merge 1 commit intoSwiftyJSON:masterfrom iwheelbuy:master
Conversation
| throw factoryError(file: file, line: line)() | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
File Line Length Violation: File should contain 400 lines or less: currently contains 1546 (file_length)
| func materialize<T>(file: String = #file, line: Int = #line) throws -> T where T: JSONMaterializableType { | ||
| return try T.implementation(self, factoryError(file: file, line: line)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| throw factoryError(file: file, line: line)() | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| func materialize<T>(file: String = #file, line: Int = #line) -> T? where T: JSONMaterializableType { | ||
| return try? T.implementation(self, factoryError(file: file, line: line)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| } | ||
|
|
||
| public extension JSON { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| } | ||
|
|
||
| extension String: JSONMaterializableType { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| } | ||
|
|
||
| extension Int: JSONMaterializableType { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| } | ||
|
|
||
| extension Double: JSONMaterializableType { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| } | ||
|
|
||
| extension Bool: JSONMaterializableType { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
| // MARK: - | ||
|
|
||
| public protocol JSONMaterializableType { | ||
|
|
There was a problem hiding this comment.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Lets say I have some struct and some enum
I want to parse the struct from JSON
JSON looks this way
This is an example how I'd parse it in a pure SwiftyJSON way
My pull request allows to do it this way
My pull request is just a proposal. Please don't merge it. Lets discuss.
Maybe... I'm missing something and there is already some way to conveniently parse and throw errors.