Author Topic: How To Test if Running on iOS, watchOS or tvOS  (Read 6554 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
How To Test if Running on iOS, watchOS or tvOS
« on: January 19, 2016, 07:31:29 PM »
You can use the following conditional compilation statements along with the os() function to determine if your app is running on iOS, watchOS, or tvOS.

In Swift:

Code: [Select]
#if os(iOS)
           
#elseif os(watchOS)
           
#elseif os(tvOS)
           
#endif

In Objective-C:

Code: [Select]
#ifdef TARGET_OS_IOS
   
#elif TARGET_OS_WATCHOS
   
#elif TARGET_OS_TV
   
#endif

All the best!
Kevin McNeish
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8