- Notifications
You must be signed in to change notification settings - Fork3.4k
Added methods that throw errors if the type is not what is expected.#487
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
jkubicek commentedMay 12, 2016
I'm strongly in favor if this, I think it's a great addition. What would you say to removing "required" from the method names? It would fit with the existing SwiftyJSON naming conventions. Also, I think the type signature ( |
charlag commentedMay 27, 2016
I would love to use this! |
CosynPa commentedJun 12, 2016
@jkubicek I think this is confusing since we already have string property. |
CosynPa commentedJun 28, 2016
I think it's better to use the |
CosynPa commentedJul 1, 2016
And |
zhigang1992 commentedSep 21, 2016
Looks interesting, can you kindly add a bit of test and update the syntax to swift3. Also, sorry for not getting to this sooner. |
ldiqual commentedNov 22, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@zhigang1992 Looking at the code, it seems that we're gonna end up with a confusing API. For instance, to unpack a string you have
I would argue that we should be as strict as possible and leave the responsibility on the user to fallback on whatever is best if the value cannot be unpacked. This is why I'm proposing this unique interface:
It covers all the cases above:
It also has the value to provide an explicit error if the unpack fail, as opposed to returning However it does introduce a code-breaking change, probably worth a SwiftyJSON v4 or something. What do you think? |
CosynPa commentedMar 21, 2017
@ldiqual This change is huge, but the benefit is not that much. I don't think the try syntax is very beginner friendly or easy to use. |
hollyschilling commentedMar 21, 2017
I must admit I all but forgot about this pull request. Although there could still be uses of this type of functionality in SwiftyJSON, my specific use case was abusing the library. As such, I built a component in myBetterLibrary that is better designed for my purpose. It is available as a Cocoapod or through SPM. It is fairly mature now, but I would love to have more eyes on it. |
kszuba commentedDec 4, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
You should consider add@hollyschilling code or add something like
@CosynPa If someone use this pod and new "not beginner friendly" func / var with try in extension is a problem, then this someone will learn how to use try catch 🥇 PS.@hollyschilling BetterLibrary, really good work :) |
Kalzem commentedFeb 1, 2018
any news on making SwiftyJSON throwable? |
kszuba commentedFeb 1, 2018
@BabyAzerty Read this article and check pod. If you will still need SwiftyJSON with throwable extension then mention me and I will share my version on GitHub |
Uh oh!
There was an error while loading.Please reload this page.
This extension is useful for non-optional properties in a failable initializer. For example: