If you want to execute that code only on iOS, then use #if os(iOS)
instead of the if #available(iOS ...)
.
This way, you are not using a dynamic check for the version of your operating system, but are compiling a different code for one OS or the other.