A handy Swift convenience thing I came up with recently (1/n):

struct Backport<Content> {
let content: Content
}

extension View {
var backport: Backport<Self> { Backport(content: self) }
}
extension Backport where Content: View {
@ViewBuilder func badge(_ count: Int) -> some View {
if #available(iOS 15, *) {
content.badge(count)
} else {
// some fallback?
content
}
}
}
Advantages:
- keep all version-specific checks in a single file
- use the same method name on all os versions
- Backport<T> isn't a view; forgetting the method = helpful compiler error
- basically a namespace for compatibility shims
- easy to ID usage: search for ".backport"
You can use this for other things too, by doing:

extension Backport where Content: UIViewController { … }

etc
When you up your minimum SDK version, go through the relevant usage sites and delete ".backport" and that's it. 🎉
This works especially well for methods and modifiers; less when when you want to backport an entirely new *type*, although you can make it work:

extension Backport<View> {
struct AsyncImage: View { … }
}

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Dave DeLong

Dave DeLong Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @davedelong

2 Apr 19
This should probably be a blog post, but I’m lazy and it’s easier to ⌘N in @tweetbot:

I had the privilege of attending and speaking at the Tokyo edition of @tryswiftconf recently. I had a fantastic and inspiring time, and want to share a couple observations with you

1/?
First off, I was totally impressed with the organization and logistics of the whole thing. It is HARD to pull a conference off well, but the @tryswiftconf team did it admirably.

2/?
Second: a huge kudos to the @tryswiftconf translators. Simultaneous translation is one of the most mentally taxing things I’ve ever done; to see these folks doing it for two days straight, at super-speed, with crazy amounts of technical language was awe-inspiring

3/?
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(