March 2020
Intermediate to advanced
392 pages
10h 10m
English
Imagine you have an enum :
enum ConnectionError: Error { case timeout case badRequest}
If you are checking an error from a result, you will do it like this:
switch (error) { case .timeout: print("timeout") case .badRequest: print("bad request") default: print("another request")
As frameworks and libraries develop, the ConnectionError enum could be extended by a future version of a framework or library. Adding another case to the enum could look like this:
enum ConnectionError: Error { case timeout case badRequest case denied}
If a newer version of a framework updates this, it will cause your old code to select the default case, and you would not even notice that there is a new case. By adding a little attribute, @unkown ...
Read now
Unlock full access