Swift’s guard and throw statements encourage a style of programming where we return early from a given scope in case of error. Returning early from a given scope poses it’s own problems though – primarily how to ensure that any resources that were created within the scope are reliably cleaned up before exiting. In this post, we look at how to solve these types of a problem using Swift’s defer
Statement.
Error Handling in Swift
As developers we have complete control of the code we write and the features we include, but despite our best efforts, things can go wrong. In this post we look at how to handle these situations by taking a look at error handling in Swift.
Swift Type Aliases
Type aliases, as the name suggests, are a way of providing an alternative name or alias for an existing Swift type and provide a convenient way for referring to existing types using a name that is more appropriate to the particular context you’re working with. In this post, we take a quick look at how to use them.
Using Custom Types as Enumeration Case Raw Values in Swift
As mentioned in my previous post, the raw values used with enumerations in Swift can be either String, Character, Int, Float or Double values. In certain cases though we might want to use custom values of our own. In this post, I thought I’d investigate a bit of a workaround.
Swift Enumerations
Enumerations, or ‘enums’ for short, are a common feature in many programming languages providing a convenient way of grouping a set of related values together into a single code construct. As we’ll see though, enumerations in Swift are much more capable than enumerations you may be used to, supporting many of the features that you would normally expect from structs and classes.
Swift Assertions
Depsite our best efforts, situations can, and sometimes do, still occur that mean that execution of our app simply can’t continue. In this article we’ll look at how to identify and debug those situations using a group of functions available in Swift called assertions.