The power and limitations of using Swift statements as expressions 0 ▲ Swift by Sundell 1 hour ago · 8 min read1579 words · Tech · hide Since Swift 5.9, it’s possible to use Swift’s if and switch statements as expressions, meaning that the results of such statements can be assigned to variables and properties, and returned from functions and closures. That might seem like a small convenience feature in isolation, but it can really help improve readability and reduce unnecessary verbosity in certain situations.So let’s explore how this language feature works, how it can be used, and also how it currently (as of Swift 6.4) cannot be used, including what some of the reasons for those limitations are.Return valuesIt’s very common for the return value of a function or computed property to depend on some form of condition, such as in the following case, where we’re returning a different string from a computed title property depending on what enum case that a given MediaType value currently matches:enum MediaType { case photo case video case audio var title: String { switch self { case .photo: return "Photo" case .video:… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town