I've already read Difference between “precondition” and “assert” in swift. But still can't draw a clear line between the (different ways of unwrapping ie guard
& !
+ error handling) vs assertions.
If I want my application to no longer work, can't I just force unwrap something and substitute as for a precondition?
- Is it because we want to stop/exit the app and basically don't want any control flow or state changing and therefore we use asserts/preconditions which also happens to come with easy logging of human readable messages (helps us to not constantly write
print
s)? - Things that we use asserts for have are vital, guard statements are eventually a control flow system that even if your function returns early doesn't necessarily mean your app should crash.
And if it's anything beyond nil
s like you want a String and the user is giving you an Int then you can use error handling.
EDIT:
I'm not after opinions, I'm asking this only to understand what convenience assertions provide over the mentioned alternatives. The numbered list is the core of my question.