在模拟器中运行时而不是在设备上运行时进行条件编译
当针对模拟器而不是我的设备时,是否有一个编译器指令可以用来编译不同的代码行。 类似于:
# IF SIMULATOR
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
# ELSE
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
# END
编辑
Is there a compiler directive I can use to compile a different line of code when targetting the simulator as opposed to my device. Something like:
# IF SIMULATOR
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
# ELSE
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
# END
EDIT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:(已弃用/已过时)这只有效了几年,并且不再有效。 (10 多年后)
根据记录,这是 Apple 在其一些官方示例代码中使用的另一种方法:
Update: (Deprecated/Obsolete) This only worked for a few years, and does not work any more. (10+ years later)
For the record, here's another method which Apple uses in some of their official Sample Code:
对于那些寻求现代 Swift 解决方案的人来说,(新)平台条件
targetEnvironment
在这里提供了明确的答案。 例如:目标环境平台条件功能是由SE-0190,自 Swift 4.1 起可用。
For those looking for a modern Swift solution, the (new) platform condition
targetEnvironment
provides the definitive answer here. For instance:The target environment platform condition feature was introduced by SE-0190 and is available since Swift 4.1.