iOS App Development Book/Video Series

General Category => FAQs => Topic started by: kjmcneish on January 19, 2016, 07:31:29 PM

Title: How To Test if Running on iOS, watchOS or tvOS
Post by: kjmcneish 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 (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 (https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8)