A more detailed explanation of this problem is here . I use this approach:
struct Platform { static let isSimulator: Bool = { var isSim = false #if arch(i386) || arch(x86_64) isSim = true #endif return isSim }() } // Elsewhere... if Platform.isSimulator { // Do one thing } else { // Do the other }
Or create a utility class:
class SimulatorUtility { class var isRunningSimulator: Bool { get { return TARGET_OS_SIMULATOR != 0
source share