ios swift 宏定义Ifdef 模拟器 真机

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

Apple Developer Documentation

猜你喜欢

转载自blog.csdn.net/linzhiji/article/details/128329443
今日推荐