Lukas Smetana2 min

Swiftly Highlights: Security, Data Persistence & Typed Throws

EngineeringMar 5, 2024

Engineering

/

Mar 5, 2024

Lukas SmetanaiOS Engineer

Share this article

Welcome to the second 2024 edition of Swiftly Highlights. As always, bringing you content from the Apple developer and Swift communities that caught our attention the most.

Grab your favorite brew, kick back and enjoy scrolling through the curated selection of articles we've picked out just for you.

Security Tips

Let’s start with security. Although iOS is generally less vulnerable than Android, it still faces some security issues. It’s the developer’s/organization’s responsibility to secure code and data communication to prevent tampering and unauthorized access. Learn what every iOS developer should take care of to minimize risks.

Daily Tweaks

As the title implies, we'll now focus on small changes and neat tricks for your daily tasks that can lead to significant improvements.

Discover a smarter way to check if numbers are even or odd in Swift. Instead of the old-school method using modulo, there's a slick function called ‘.isMultiple(of:)’ that does the job more cleanly and clearly. It's a simple change but makes your code look much better.

Next, we look at optimizing memory usage with booleans. A boolean (Bool) is a simple type that represents logical true or false. In Swift, booleans are one byte in size. Generally, it’s not a big deal — but when working with a large array of booleans, we can end up with some unused memory. Using this technique, we can reduce the amount of used memory by eight times.

At one point or another, you may have seen one of the most typical Swift errors: “Protocol ‘XX’ can only be used as a generic constraint because it has Self or associated type requirements.” Until not so long ago, it was impossible to “fix”; you had to rethink your code by avoiding casting an object to an existential. Thankfully, this issue is now over! See this great article by Swift/Unwrap and learn how you can leverage ‘any’ keyword and open existentials to solve this common issue.

Even though submitting your app to the App Store might not be on your daily chores list, it's valuable to know how to properly create App Preview Videos. Not only do you have to attract your potential users with the content, but you also have to follow Apple's App Preview Specifications. The developer tool RocketSim helps you speed up this process. (Nope, not a paid promotion. Just big fans.)

Data Persistence

Developers these days have multiple choices for dealing with data persistence on Apple platforms. SwiftData is a trending native solution, but there are other well-known solutions. Read about a brief history of the adoption of one of the most used data-persistence frameworks, Realm, and how to enhance SwiftUI data management with it.

Anyone who's been dealing with data persistence will sooner or later encounter the topic of data migration. And if your weapon of choice is Apple's own Core Data framework, you might find this Custom Core Data migrations guide very handy.

Typed Throws in Swift

The future Swift version will include typed throws, as they were in high demand by the community. At its core, typed throws will allow us to inform callers of throwing functions which errors they might receive as a result of calling a function. Learn more about today’s error handling situation, the accepted Swift update and possible ways of implementation into your codebase — as well as its limitations — in Donny Wals's new article or video.

Swift 6.0

And since we mentioned the new Swift version: the Swift 6.0 release process has been detailed on the Swift Forums. Snapshots of Swift 6.0 are being regularly posted for continuous integration testing, and the release/6.0 branch will be cut from the main branch on March 15, 2024. This branch will include changes slated for Swift 6.0, with further changes subject to pull request acceptance based on specific criteria.

Next Time

As we wrap up this month with our 49th edition, we can hardly contain our excitement for what's next. Yes, you guessed it — our upcoming 50th edition is just around the corner, and we promise it's going to be special!

Share this article



Sign up to our newsletter

Monthly updates, real stuff, our views. No BS.