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
Generic materialize function with throwable behaviour for throwable initializers #890
base: master
Are you sure you want to change the base?
Conversation
throw factoryError(file: file, line: line)() | ||
} | ||
} | ||
} |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
throw factoryError(file: file, line: line)() | ||
} | ||
} | ||
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
public extension JSON { | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension String: JSONMaterializableType { | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension Int: JSONMaterializableType { | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension Double: JSONMaterializableType { | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension Bool: JSONMaterializableType { | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
// MARK: - | ||
|
||
public protocol JSONMaterializableType { | ||
|
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.
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.