#if (arch(i386) || arch(x86_64)) && os(iOS)
...模擬器
#else
...iOS 實體機
#endif
Detect the watchOS simulator
#if (arch(i386) || arch(x86_64)) && os(watchOS)
...模擬器
#else
...watchOS 實體機
#endif
Detect the tvOS simulator
#if (arch(i386) || arch(x86_64)) && os(tvOS)
...
#endif
Or, even, detect any simulator
#if (arch(i386) || arch(x86_64)) && (os(iOS) || os(watchOS) || os(tvOS))
...
#endif
Static let isSimulator: Bool = { var isSim = false #if arch(i386) || arch(x86_64) isSim = true #endif return isSim }( ) if Platform.isSimulator { print("Running on Simulator") } else { // Do the other }
https://stackoverflow.com/questions/24869481/detect-if-app-is-being-built-for-device-or-simulator-in-swift