Swift Tips
Enabling upcoming feature flags in an SPM package
Published on: May 19, 2025As Swift evolves, a lot of new evolution proposals get merged into the language. Eventually these new language versions get shipped with Xcode, but sometimes you might want to try out Swift toolchains before they're available inside of Xcode. For example, I'm currently experimenting with Swift 6.2's upcoming features to see how they will impact certain coding patterns once 6.2 becomes available for everybody. This means that I'm trying out proposals like SE-0461 that can change where nonisolated async functions run. This specific proposal requires me to turn on an upcoming feature flag. To do this in SPM, we need...
Read more...How to check if two date ranges overlap in Swift
Published on: January 17, 2020Dates in Swift can be compared to each other. This allows you to check whether one date comes before or after another date: if dateOne > dateTwo { print("dateOne comes after dateTwo") } else if dateOne < dateTwo { print("dateOne comes before dateTwo") } else if dateOne == dateTwo { print("dateOne is equal to dateTwo") } You can also use dates in Swift to create ranges. And when you have one range, you can check whether it overlaps with another date. Let's look at an example: struct Meeting { let startDate: Date let endDate: Date } func doMeetingsOverlap(_ meetingOne: Meeting,...
Read more...Generics in Swift explained
Published on: December 5, 2019Whenever we write code, we want our code to be well-designed. We want it to be flexible, elegant and safe. We want to make sure that Swift’s type system and the compiler catch as many of our mistakes as possible. It’s especially interesting how Swift’s type system can help us avoid obvious errors. For example, Swift won’t allow you to assign an Int to a String property like this: var anInt = 10 anInt = "Hello, World!" The Swift compiler would show you an error that explains that you can’t assign a String to an Int and you’d understand this....
Read more...