What’s new in Swift 5.0
As we know Swift 5.0 is realised, we will take brief tour of new features added as developer prospect, means functions or properties we used to use in our daily programming.
I went through this, tried new points, simplify them for you.
you can refer other sites or articles for more and deep information.
ABI Stability
Swift is declared to be ABI stable, the code written from this point on would be compatible with the newer versions of the language and the developer won’t have to update all the external dependencies of the project while migrating to a new version of Swift.
Raw strings
Place # symbols before your strings, like this:
Checking for integer multiples
Introduced new keyword isMultiple.
Allowing us to check whether one number is a multiple of another in a much clearer way than using the division remainder operation
Transforming and unwrapping dictionary values with compactMapValues()
To unwrap optionals and discard nil values
Handling future enum cases
@unknown we can only add in front of default.
One of Swift’s security features is that it requires all switch statements to be exhaustive — that they must cover all cases. While this works well from a safety perspective, it causes compatibility issues when new cases are added in the future: a system framework might send something different that you hadn’t catered for, or code you rely on might add a new case and cause your compile to break because your switch is no longer exhaustive.
With the @unknown
attribute we can now distinguish between two subtly different scenarios: “this default case should be run for all other cases because I don’t want to handle them individually,” and “I want to handle all cases individually, but if anything comes up in the future use this rather than causing an error.”
@unknown default
matches any value,However, the compiler will produce a warning if all known elements of the enum have not already been matched. This is a warning rather than an error so that adding new elements to the enum remains a source-compatible change.
Result type
It’s giving us a simpler, clearer way of handling errors in complex code such as asynchronous APIs.
Result is made up of enum, condition while used Result type is .failure state must require a Error type.
Happy Coding.