简体   繁体   English

在为多个版本进行编译时,如何包含对仅在一个操作系统版本中存在的方法的调用?

[英]How do I include calls to methods only present in one operating system version when compiling for multiple versions?

I have an app that is being compiled with a minimum system requirement of Tiger (OS X 10.4), but I need to include some code to deal with Spaces if the app is executing on Leopard (OS X 10.5). 我有一个使用最低系统要求Tiger(OS X 10.4)编译的应用程序,但是如果该应用程序在Leopard(OS X 10.5)上执行,则需要包含一些代码来处理Spaces。

How do I do this? 我该怎么做呢?

(The call I need to make is to -[NSWindow setCollectionBehavior:] ). (我需要拨打-[NSWindow setCollectionBehavior:] )。

  1. Set your Base SDK (for all configurations of the target you're building) to the version of the OS that includes the call. 将您的基本SDK(针对要构建的目标的所有配置)设置为包含调用的OS版本。
  2. Set the Deployment Version to the earliest OS you want your code to launch on. 将部署版本设置为要在其上启动代码的最早的OS。
  3. For all calls that don't exist in earlier versions of the OS, you must test before you call, either by using respondsToSelector: (for methods) or testing against nil (for functions and statics). 对于操作系统早期版本中不存在的所有调用,您必须在调用之前进行测试,方法是使用responsToSelector :(对于方法)或针对nil(对于函数和静态函数)进行测试。 You can if you like do a check for the OS version, but it's more robust to check the specific call. 您可以根据需要检查操作系统的版本,但是检查特定呼叫更为可靠。

The Cross-Development Programming Guide describes the techniques in detail. 跨开发编程指南》详细介绍了这些技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于操作系统版本的条件方法 - Conditional Methods based on Operating System Version 我如何一个接一个地呈现多个UIAlertController? - How do I present multiple UIAlertController one after another? 当存在虚拟键盘时,如何仅显示UIToolBar - How do I only show UIToolBar when virtual keyboard is present 如何获取Mac操作系统的实际名称而不是版本? - How to get actual name of Mac Operating System instead of version? 如何使用适用于Linux的g ++编译C ++程序以在Windows操作系统中工作? - how do i compile a C++program to work in the windows operating system using g++ for linux? 目标C:我正在编译的JSON库版本在通过.a连接的另一个库中,如何解决冲突? - Objective C: Version of JSON library I'm compiling in present in another library I'm linking in via .a, how to resolve conflict? 为什么iOS SDK和iOS操作系统版本相互影响?或者:什么是iOS SDK? - Why do iOS SDK and iOS Operating System version affect each other? Or: What IS an iOS SDK? 发现对早期iOS版本中不可用的方法的调用 - Discover calls to methods not available in earlier iOS versions 我什么时候发布传递给多个方法的NSMutableArray实例? - When do I release an NSMutableArray instance passed to multiple methods? 编译Swift代码时可以包含一个ObjC类吗? - Can I include a single ObjC class when compiling Swift code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM