As nice as it is to share as much as possible #swiftui between the iPad and iOS, there are still more than a few spots when it makes sense to optimise for either. Checking `UIDevice.current.userInterfaceIdiom` is the way:

”For universal applications, you can use this property to tailor the behavior of your application for a specific type of device.”

developer.apple.com/documentat
developer.apple.com/documentat

Still frustrating that I can’t just `#if os(iPadOS)` because although my functions are helpful, they’re not compile friendly.

@Mecid good question. Firstly, unfamiliar with the technique, but looking into now. For the Mac it’s a Catalyst-only. So, in this case, do you mean I refer to it to differentiate between iPad and iPhone?

@Mecid that’s neat: I check for iOS and within I differentiate by size (not platform). But it doesn’t cater for the case when I want the iPad and Mac to share UI code? Because an #if iOS directive will be true for iPad. What is ideal would be a compile friendly way to fork/bundle Mac and iPadOS SwiftUI.

i.e. I want the iPad and Mac UIs to share the same _structure_ but there are smaller details within that can vary based on what APIs are supported per each target.

Follow

@bardi @Mecid when sizes classes aren't enough, I've found it useful to expose a platform idiom in the environment. This obviously isn't a substitute for platform directives if the API is unavailable, but it's useful to make small UI tweaks.

gist.github.com/phillipcaudell

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.