Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if my code is running on WatchKit or iOS using Swift?

I have a class with both targets, and I want to know if I'm running it's methods on Watch or iPhone target.

Please, just Swift answers.

like image 696
Hugo Alonso Avatar asked Dec 07 '15 19:12

Hugo Alonso


1 Answers

Something like this

#if os(iOS)
  print("iOS")
#else 
  print("anything else")
#endif

Or even this

if #available(watchOS 2,*){}
if #available(iOS 9, *){}
like image 89
rkyr Avatar answered Oct 13 '22 11:10

rkyr