John Tracid
John Tracid

Reputation: 4046

How to have different toggle style for iOS and macOS

I'm trying to have toggle with native style for iOS (switch) and macOS (checkbox) in my universal app. This code does not work:

#if targetEnvironment(macCatalyst)
private let toggleStyle = CheckboxToggleStyle()
#else
private let toggleStyle = SwitchToggleStyle()
#endif

'CheckboxToggleStyle' is unavailable in iOS

Was thinking that macros should compile correct path for each target.

Upvotes: 2

Views: 1121

Answers (1)

Asperi
Asperi

Reputation: 257711

CheckboxToggleStyle is for macOS only... see below API declaration. macCatalyst is actually environment simulating iOS on macOS, but from API perspective it is iOS

/// A `ToggleStyle` represented by a leading checkbox.
@available(OSX 10.15, *)
@available(iOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
public struct CheckboxToggleStyle : ToggleStyle {

Upvotes: 2

Related Questions