gpt4 book ai didi

ios - 如何为不同版本的 Xcode 编写条件语句

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:08 25 4
gpt4 key购买 nike

我正在使用两台不同的计算机开发应用程序。一台是我的家用机器,它是一台较旧的 MacBook Pro,但具有最新的操作系统并运行 Xcode 7.3。我使用的第二台机器是我的工作机器,它是全新的,速度快如闪电,但仅限于 Yosemite 和 Xcode 7.2.1。

我最近在运行 Xcode 7.2.1 的机器上遇到构建错误,但应用程序在运行较新 Xcode 的机器上构建和运行没有错误。由于顽固的 IT 策略,我无法升级工作机器,而且我真的(真的)不想将我的家用机器降级到 Xcode 7.2.1。

所以我想做的是编写类似于以下伪代码的条件:

if Xcode.version == 7.3
// Run this version of the statement
refreshControl.addTarget(self, action: #selector(ReadingTVC.pullToRefreshTableView), forControlEvents: UIControlEvents.ValueChanged)
if Xcode.version == 7.2.1
// Run this different version of the statement
// I still need to figure out how to rewrite the statement for 7.2.1

这可能吗?我在 Apple 文档中找到了以下内容,但没有 Xcode 版本的选项。仅 swift()、os() 或 arch():

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID539

提前致谢!

最佳答案

您应该只使用 swift() 来检查 swift 的版本,因为 Xcode 7.3 附带 Swift 2.2 而 Xcode 7.2.1 附带 Swift 2.1.x。

对于您的代码,由于 swift() 是在 swift 2.2 中引入的,您需要更改在两个版本中都有效的使用代码,如下所示(假设 ReadingTVCself):

// For both swift 2.1.x and swift 2.2. In swift 2.2, this will pop a 
// warning and ask you to fix. But you can wait until you work computer
// updated Xcode version to 7.3. You will be force to change when
// upgrade to swift 3.0 since the old string based api will be removed.
// Currently it is just marked as deprecated.
refreshControl.addTarget(self, action: "pullToRefreshTableView", forControlEvents: UIControlEvents.ValueChanged)

关于ios - 如何为不同版本的 Xcode 编写条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36614612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com