在Ubuntu上进行Swift系统版本检查(Swift system version checking on Ubuntu)

系统教程 行业动态 更新时间:2024-06-14 16:59:22
在Ubuntu上进行Swift系统版本检查(Swift system version checking on Ubuntu)

我知道Swift有预处理器指令来检查操作系统:

#if os(iOS) ... #elseif os(OSX) ... #endif

但是,在网上搜索后,我发现没有什么可以检查操作系统是Ubuntu。 有没有办法做到这一点? 我知道swift最近才开始研究Ubuntu,所以我意识到在撰写本文时可能没有办法。

I know Swift has preprocessor directives that check the OS :

#if os(iOS) ... #elseif os(OSX) ... #endif

But, after searching online, I've found nothing to check is the OS is Ubuntu. Is there a way of doing that ? I know swift has only recently been working on Ubuntu, so I realize that there may not be a way as of this writing.

最满意答案

在Swift中, #if ... #endif不是预处理程序语句,而是包含“条件编译块” 。 os()平台条件的有效参数(目前)记录为

macOS, iOS, watchOS, tvOS, Linux

因此#if os(Linux)检查Linux平台。 一个典型的例子是

#if os(Linux) import Glibc #else import Darwin #endif

在Linux和Apple平台上从C库导入函数。

In Swift, #if ... #endif are not preprocessor statements, but enclose a "Conditional Compilation Block". The valid arguments for the os() platform condition are (currently) documented as

macOS, iOS, watchOS, tvOS, Linux

Therefore #if os(Linux) checks for a Linux platform. A typical example is

#if os(Linux) import Glibc #else import Darwin #endif

to import functions from the C library on both Linux and Apple platforms.

更多推荐

本文发布于:2023-04-16 19:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/1e454301e1bfc51d570c135710114d2e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   系统   Swift   Ubuntu   version

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!