swift
#if (arch(i386) || arch(x86_64)) && os(iOS)
...
#endif
swift 4.1 后
#if targetEnvironment(simulator)
// your simulator code
#else
// your real device code
#endif
原来可以这么写
#if TARGET_OS_IPHONE
#endif
#if !TARGET_IPHONE_SIMULATOR
#endif
参考
ios - How to detect if app is being built for device or simulator in Swift - Stack Overflow