4

Using global variable, this works:

@available(iOS 16.1, *)
var activity: Activity<RememberAttributes>?

If I want to try making it into a state variable, but I will get this error "'Activity' is only available in iOS 16.1 or newer".

Is it possible to create a state variable only when in iOS 16.1?

Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88

1 Answers1

2

No. You need to define your variables at compile-time. @available is evaluated at run time. The best you're going to be able to do is to make the variable an optional, and assign it a non-nil value from code wrapped in an @available. –

Duncan C
  • 128,072
  • 22
  • 173
  • 272